Skip to content

Commit

Permalink
fix: allow Binaries to define metadata and metadata schema
Browse files Browse the repository at this point in the history
  • Loading branch information
loopingz committed Dec 4, 2023
1 parent 439d2fb commit 2001b1e
Show file tree
Hide file tree
Showing 11 changed files with 2,610 additions and 212 deletions.
12 changes: 4 additions & 8 deletions packages/async/webda.module.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,13 @@
"url": {
"type": "string",
"description": "URL to expose job status report hook",
"default": "/async/jobs"
},
"store": {
"type": "string",
"description": "Store name to use for async actions",
"default": "AsyncActions"
"default": "/async/jobs",
"deprecated": "will be removed in 4.0 to only use object AsyncAction"
},
"binaryStore": {
"type": "string",
"description": "If we want to expose a way to upload/download binary for the job\n\nIt will expose a /download and /upload additional url"
"description": "If we want to expose a way to upload/download binary for the job\n\nIt will expose a /download and /upload additional url",
"deprecated": "will be removed in 4.0 to only use object AsyncAction"
},
"localLaunch": {
"type": "boolean",
Expand Down Expand Up @@ -279,7 +276,6 @@
"logsLimit",
"queue",
"runners",
"store",
"type",
"url"
],
Expand Down
56 changes: 56 additions & 0 deletions packages/core/src/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,62 @@ class CoreTest extends WebdaTest {
assert.strictEqual(this.ctx.getParameters().provider, undefined);
}

@test
validateSubSchema() {
const app = this.webda.getApplication();
if (!app.hasSchema("obj1")) {
app.registerSchema("obj1", {
type: "object",
properties: {
uuid: {
type: "string"
},
assets: {
$ref: "#/definitions/Binaries"
}
},
definitions: {
Binaries: {
type: "object",
properties: {
upload: {}
},
required: ["upload"],
description: "Define a collection of Binary with a Readonly and the upload method"
}
},
required: ["uuid"]
});
}
if (!app.hasSchema("obj2")) {
app.registerSchema("obj2", {
type: "object",
properties: {
uuid: {
type: "string"
},
assets: {
$ref: "#/definitions/Binaries",
readOnly: true
}
},
definitions: {
Binaries: {
type: "object",
properties: {
upload: {}
},
required: ["upload"],
description: "Define a collection of Binary with a Readonly and the upload method"
}
},
required: ["uuid"]
});
}
this.webda.validateSchema("obj1", { uuid: "test" });
this.webda.validateSchema("obj2", { uuid: "test2" });
}

@test
covValidateSchema() {
assert.strictEqual(this.webda.validateSchema("test", {}), null);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class BinariesImpl<T = any> extends Array<BinariesItem<T>> {
/**
* Define a collection of Binary with a Readonly and the upload method
*/
export type Binaries = Readonly<Array<BinariesItem>> & { upload: (file: BinaryFile) => Promise<void> };
export type Binaries<T = any> = Readonly<Array<BinariesItem<T>>> & { upload: (file: BinaryFile) => Promise<void> };

export class BinaryParameters extends ServiceParameters {
/**
Expand Down
6 changes: 4 additions & 2 deletions packages/core/webda.module.json
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,8 @@
"description": "UUID of the object"
},
"_user": {
"type": "string"
"type": "string",
"readOnly": true
},
"public": {
"type": "boolean",
Expand Down Expand Up @@ -2317,7 +2318,8 @@
"description": "UUID of the object"
},
"_user": {
"type": "string"
"type": "string",
"readOnly": true
},
"public": {
"type": "boolean",
Expand Down
173 changes: 142 additions & 31 deletions packages/gcp/webda.module.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
"retry": {
"anyOf": [
{
"$ref": "#/definitions/Partial%3Cclass-1723313223-735-3044-1723313223-0-15050%3E"
"$ref": "#/definitions/Partial%3Cclass-657338214-735-3044-657338214-0-15050%3E"
},
{
"type": "null"
Expand Down Expand Up @@ -637,7 +637,26 @@
"type": "number"
},
{
"$ref": "#/definitions/Long"
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
{
"type": "string"
Expand Down Expand Up @@ -670,7 +689,26 @@
"type": "number"
},
{
"$ref": "#/definitions/Long"
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
{
"type": "string"
Expand Down Expand Up @@ -768,7 +806,26 @@
"type": "number"
},
{
"$ref": "#/definitions/Long"
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
{
"type": "string"
Expand Down Expand Up @@ -855,7 +912,26 @@
"type": "number"
},
{
"$ref": "#/definitions/Long"
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
{
"type": "string"
Expand Down Expand Up @@ -893,7 +969,26 @@
"type": "number"
},
{
"$ref": "#/definitions/Long"
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
{
"type": "string"
Expand Down Expand Up @@ -954,7 +1049,26 @@
"type": "number"
},
{
"$ref": "#/definitions/Long"
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
{
"type": "string"
Expand Down Expand Up @@ -1015,7 +1129,26 @@
"type": "number"
},
{
"$ref": "#/definitions/Long"
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
{
"type": "string"
Expand Down Expand Up @@ -1049,7 +1182,7 @@
}
}
},
"Partial<class-1723313223-735-3044-1723313223-0-15050>": {
"Partial<class-657338214-735-3044-657338214-0-15050>": {
"type": "object",
"properties": {
"retryCodes": {
Expand Down Expand Up @@ -1117,28 +1250,6 @@
],
"description": "State enum."
},
"Long": {
"type": "object",
"properties": {
"high": {
"type": "number",
"description": "The high 32 bits as a signed value."
},
"low": {
"type": "number",
"description": "The low 32 bits as a signed value."
},
"unsigned": {
"type": "boolean",
"description": "Whether unsigned or not."
}
},
"required": [
"high",
"low",
"unsigned"
]
},
"google.pubsub.v1.CloudStorageConfig.State": {
"type": "number",
"enum": [
Expand Down
3 changes: 2 additions & 1 deletion packages/hawk/webda.module.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"description": "UUID of the object"
},
"_user": {
"type": "string"
"type": "string",
"readOnly": true
},
"public": {
"type": "boolean",
Expand Down
Loading

0 comments on commit 2001b1e

Please sign in to comment.