@aws-amplify/data-schema 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/CustomOperation.js +46 -0
- package/dist/cjs/CustomOperation.js.map +1 -1
- package/dist/cjs/CustomType.js +32 -0
- package/dist/cjs/CustomType.js.map +1 -1
- package/dist/cjs/Handler.js +62 -0
- package/dist/cjs/Handler.js.map +1 -1
- package/dist/cjs/ModelRelationalField.js +82 -3
- package/dist/cjs/ModelRelationalField.js.map +1 -1
- package/dist/esm/CustomOperation.d.ts +46 -0
- package/dist/esm/CustomOperation.mjs +46 -0
- package/dist/esm/CustomOperation.mjs.map +1 -1
- package/dist/esm/CustomType.d.ts +32 -0
- package/dist/esm/CustomType.mjs +32 -0
- package/dist/esm/CustomType.mjs.map +1 -1
- package/dist/esm/Handler.d.ts +62 -0
- package/dist/esm/Handler.mjs +62 -0
- package/dist/esm/Handler.mjs.map +1 -1
- package/dist/esm/ModelField.d.ts +1 -1
- package/dist/esm/ModelRelationalField.d.ts +83 -4
- package/dist/esm/ModelRelationalField.mjs +82 -3
- package/dist/esm/ModelRelationalField.mjs.map +1 -1
- package/dist/esm/RefType.d.ts +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/CustomOperation.ts +46 -0
- package/src/CustomType.ts +32 -0
- package/src/Handler.ts +62 -0
- package/src/ModelField.ts +1 -1
- package/src/ModelRelationalField.ts +83 -4
- package/src/RefType.ts +1 -1
|
@@ -51,14 +51,60 @@ function _custom(typeName, brand) {
|
|
|
51
51
|
}, brand);
|
|
52
52
|
return { ...builder, data };
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Use a custom query to define an API request that will retrieve backend data.
|
|
56
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}
|
|
57
|
+
* @example
|
|
58
|
+
* const schema = a.schema({
|
|
59
|
+
* echo: a
|
|
60
|
+
* .query()
|
|
61
|
+
* .arguments({ content: a.string() })
|
|
62
|
+
* .returns(a.ref('EchoResponse'))
|
|
63
|
+
* .authorization(allow => [allow.publicApiKey()])
|
|
64
|
+
* // 3. set the function has the handler
|
|
65
|
+
* .handler(a.handler.function(echoHandler)),
|
|
66
|
+
*
|
|
67
|
+
* EchoResponse: a.customType({
|
|
68
|
+
* content: a.string(),
|
|
69
|
+
* executionDuration: a.float()
|
|
70
|
+
* }),
|
|
71
|
+
* });
|
|
72
|
+
* @returns a custom query
|
|
73
|
+
*/
|
|
54
74
|
function query() {
|
|
55
75
|
return _custom('Query', queryBrand);
|
|
56
76
|
}
|
|
57
77
|
exports.query = query;
|
|
78
|
+
/**
|
|
79
|
+
* Use a custom mutation to define an API request that will modify backend data or trigger a subscription event.
|
|
80
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}
|
|
81
|
+
* @example
|
|
82
|
+
* likePost: a
|
|
83
|
+
* .mutation()
|
|
84
|
+
* .arguments({ postId: a.string() })
|
|
85
|
+
* .returns(a.ref('Post'))
|
|
86
|
+
* .authorization(allow => [allow.publicApiKey()])
|
|
87
|
+
* .handler(a.handler.function(echoHandler))
|
|
88
|
+
* @returns a custom mutation
|
|
89
|
+
*/
|
|
58
90
|
function mutation() {
|
|
59
91
|
return _custom('Mutation', mutationBrand);
|
|
60
92
|
}
|
|
61
93
|
exports.mutation = mutation;
|
|
94
|
+
/**
|
|
95
|
+
* Define a custom subscription to receive an event when a mutation is triggered
|
|
96
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-subscription/}
|
|
97
|
+
* @example
|
|
98
|
+
* // Subscribe to incoming messages
|
|
99
|
+
* receive: a.subscription()
|
|
100
|
+
* // subscribes to the 'publish' mutation
|
|
101
|
+
* .for(a.ref('publish'))
|
|
102
|
+
* // subscription handler to set custom filters
|
|
103
|
+
* .handler(a.handler.custom({entry: './receive.js'}))
|
|
104
|
+
* // authorization rules as to who can subscribe to the data
|
|
105
|
+
* .authorization(allow => [allow.publicApiKey()]),
|
|
106
|
+
* @returns a custom subscription
|
|
107
|
+
*/
|
|
62
108
|
function subscription() {
|
|
63
109
|
return _custom('Subscription', subscriptionBrand);
|
|
64
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomOperation.js","sources":["../../src/CustomOperation.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.subscription = exports.mutation = exports.query = exports.CustomOperationNames = void 0;\nconst util_1 = require(\"./util\");\nconst Authorization_1 = require(\"./Authorization\");\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nexports.CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...(0, util_1.brand)(brandValue) };\n}\nfunction _custom(typeName, brand) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n };\n const builder = brandedBuilder({\n arguments(args) {\n data.arguments = args;\n return this;\n },\n returns(returnType) {\n data.returnType = returnType;\n return this;\n },\n authorization(callback) {\n const rules = callback(Authorization_1.allowForCustomOperations);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n handler(handlers) {\n data.handlers = Array.isArray(handlers)\n ? handlers\n : [handlers];\n return this;\n },\n for(source) {\n data.subscriptionSource = Array.isArray(source) ? source : [source];\n return this;\n },\n }, brand);\n return { ...builder, data };\n}\nfunction query() {\n return _custom('Query', queryBrand);\n}\nexports.query = query;\nfunction mutation() {\n return _custom('Mutation', mutationBrand);\n}\nexports.mutation = mutation;\nfunction subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\nexports.subscription = subscription;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAA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CustomOperation.js","sources":["../../src/CustomOperation.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.subscription = exports.mutation = exports.query = exports.CustomOperationNames = void 0;\nconst util_1 = require(\"./util\");\nconst Authorization_1 = require(\"./Authorization\");\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nexports.CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...(0, util_1.brand)(brandValue) };\n}\nfunction _custom(typeName, brand) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n };\n const builder = brandedBuilder({\n arguments(args) {\n data.arguments = args;\n return this;\n },\n returns(returnType) {\n data.returnType = returnType;\n return this;\n },\n authorization(callback) {\n const rules = callback(Authorization_1.allowForCustomOperations);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n handler(handlers) {\n data.handlers = Array.isArray(handlers)\n ? handlers\n : [handlers];\n return this;\n },\n for(source) {\n data.subscriptionSource = Array.isArray(source) ? source : [source];\n return this;\n },\n }, brand);\n return { ...builder, data };\n}\n/**\n * Use a custom query to define an API request that will retrieve backend data.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * const schema = a.schema({\n * echo: a\n * .query()\n * .arguments({ content: a.string() })\n * .returns(a.ref('EchoResponse'))\n * .authorization(allow => [allow.publicApiKey()])\n * // 3. set the function has the handler\n * .handler(a.handler.function(echoHandler)),\n *\n * EchoResponse: a.customType({\n * content: a.string(),\n * executionDuration: a.float()\n * }),\n * });\n * @returns a custom query\n */\nfunction query() {\n return _custom('Query', queryBrand);\n}\nexports.query = query;\n/**\n * Use a custom mutation to define an API request that will modify backend data or trigger a subscription event.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * likePost: a\n * .mutation()\n * .arguments({ postId: a.string() })\n * .returns(a.ref('Post'))\n * .authorization(allow => [allow.publicApiKey()])\n * .handler(a.handler.function(echoHandler))\n * @returns a custom mutation\n */\nfunction mutation() {\n return _custom('Mutation', mutationBrand);\n}\nexports.mutation = mutation;\n/**\n * Define a custom subscription to receive an event when a mutation is triggered\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-subscription/}\n * @example\n * // Subscribe to incoming messages\n * receive: a.subscription()\n * // subscribes to the 'publish' mutation\n * .for(a.ref('publish'))\n * // subscription handler to set custom filters\n * .handler(a.handler.custom({entry: './receive.js'}))\n * // authorization rules as to who can subscribe to the data\n * .authorization(allow => [allow.publicApiKey()]),\n * @returns a custom subscription\n */\nfunction subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\nexports.subscription = subscription;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AAChG,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAC1C,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAChD,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AACxD,OAAO,CAAC,oBAAoB,GAAG;AAC/B,IAAI,OAAO;AACX,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,CAAC,CAAC;AACF,SAAS,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;AAC7C,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,UAAU,CAA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G,CAAC,MAAM,CAAC,CAAC;AAChF,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,KAAK,EAAE,KAAK,CAAC,CAAC;AACd,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,KAAK,GAAG;AACjB,IAAI,OAAO,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC;AACD,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,QAAQ,GAAG;AACpB,IAAI,OAAO,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAC9C,CAAC;AACD,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,YAAY,GAAG;AACxB,IAAI,OAAO,OAAO,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;AACtD,CAAC;AACD,OAAO,CAAC,YAAY,GAAG,YAAY;;"}
|
package/dist/cjs/CustomType.js
CHANGED
|
@@ -9,6 +9,38 @@ function _customType(fields) {
|
|
|
9
9
|
};
|
|
10
10
|
return { data };
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Define a custom type. This type represents an inline, typed JSON object.
|
|
14
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/add-fields/#specify-a-custom-field-type}
|
|
15
|
+
* @param fields the fields to be added to the custom type
|
|
16
|
+
* @returns a custom type
|
|
17
|
+
* @example
|
|
18
|
+
* a.schema({
|
|
19
|
+
* Post: a.model({
|
|
20
|
+
* location: a.customType({
|
|
21
|
+
* lat: a.float(),
|
|
22
|
+
* long: a.float(),
|
|
23
|
+
* }),
|
|
24
|
+
* content: a.string(),
|
|
25
|
+
* }),
|
|
26
|
+
* });
|
|
27
|
+
* @example
|
|
28
|
+
* a.schema({
|
|
29
|
+
* Location: a.customType({
|
|
30
|
+
* lat: a.float(),
|
|
31
|
+
* long: a.float(),
|
|
32
|
+
* }),
|
|
33
|
+
*
|
|
34
|
+
* Post: a.model({
|
|
35
|
+
* location: a.ref('Location'),
|
|
36
|
+
* content: a.string(),
|
|
37
|
+
* }),
|
|
38
|
+
*
|
|
39
|
+
* User: a.model({
|
|
40
|
+
* lastKnownLocation: a.ref('Location'),
|
|
41
|
+
* }),
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
12
44
|
function customType(fields) {
|
|
13
45
|
return _customType(fields);
|
|
14
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomType.js","sources":["../../src/CustomType.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.customType = void 0;\nfunction _customType(fields) {\n const data = {\n fields,\n type: 'customType',\n };\n return { data };\n}\nfunction customType(fields) {\n return _customType(fields);\n}\nexports.customType = customType;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B,SAAS,WAAW,CAAC,MAAM,EAAE;AAC7B,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,IAAI,EAAE,YAAY;AAC1B,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;AACpB,CAAC;AACD,SAAS,UAAU,CAAC,MAAM,EAAE;AAC5B,IAAI,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AACD,OAAO,CAAC,UAAU,GAAG,UAAU;;"}
|
|
1
|
+
{"version":3,"file":"CustomType.js","sources":["../../src/CustomType.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.customType = void 0;\nfunction _customType(fields) {\n const data = {\n fields,\n type: 'customType',\n };\n return { data };\n}\n/**\n * Define a custom type. This type represents an inline, typed JSON object.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/add-fields/#specify-a-custom-field-type}\n * @param fields the fields to be added to the custom type\n * @returns a custom type\n * @example\n * a.schema({\n * Post: a.model({\n * location: a.customType({\n * lat: a.float(),\n * long: a.float(),\n * }),\n * content: a.string(),\n * }),\n * });\n * @example\n * a.schema({\n * Location: a.customType({\n * lat: a.float(),\n * long: a.float(),\n * }),\n *\n * Post: a.model({\n * location: a.ref('Location'),\n * content: a.string(),\n * }),\n *\n * User: a.model({\n * lastKnownLocation: a.ref('Location'),\n * }),\n * });\n */\nfunction customType(fields) {\n return _customType(fields);\n}\nexports.customType = customType;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B,SAAS,WAAW,CAAC,MAAM,EAAE;AAC7B,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,IAAI,EAAE,YAAY;AAC1B,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;AACpB,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,UAAU,CAAC,MAAM,EAAE;AAC5B,IAAI,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AACD,OAAO,CAAC,UAAU,GAAG,UAAU;;"}
|
package/dist/cjs/Handler.js
CHANGED
|
@@ -28,6 +28,33 @@ function sqlReference(sqlFilePath) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
const customHandlerBrand = 'customHandler';
|
|
31
|
+
/**
|
|
32
|
+
* Use a custom JavaScript resolver to handle a query, mutation, or subscription.
|
|
33
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/#step-2---configure-custom-business-logic-handler-code}
|
|
34
|
+
* @param customHandler `{ entry: "path-to-javascript-resolver-file.js", dataSource: "Data Source name added via "backend.data.add*DataSoruce(...)"}`
|
|
35
|
+
* @returns A JavaScript resolver attached to the query, mutation, or subscription.
|
|
36
|
+
* @example
|
|
37
|
+
* const schema = a.schema({
|
|
38
|
+
* Post: a.model({
|
|
39
|
+
* content: a.string(),
|
|
40
|
+
* likes: a.integer()
|
|
41
|
+
* .authorization(allow => [allow.authenticated().to(['read'])])
|
|
42
|
+
* }).authorization(allow => [
|
|
43
|
+
* allow.owner(),
|
|
44
|
+
* allow.authenticated().to(['read'])
|
|
45
|
+
* ]),
|
|
46
|
+
*
|
|
47
|
+
* likePost: a
|
|
48
|
+
* .mutation()
|
|
49
|
+
* .arguments({ postId: a.id() })
|
|
50
|
+
* .returns(a.ref('Post'))
|
|
51
|
+
* .authorization(allow => [allow.authenticated()])
|
|
52
|
+
* .handler(a.handler.custom({
|
|
53
|
+
* dataSource: a.ref('Post'),
|
|
54
|
+
* entry: './increment-like.js'
|
|
55
|
+
* }))
|
|
56
|
+
* });
|
|
57
|
+
*/
|
|
31
58
|
function custom(customHandler) {
|
|
32
59
|
// used to determine caller directory in order to resolve relative path downstream
|
|
33
60
|
const stack = new Error().stack;
|
|
@@ -37,6 +64,41 @@ function custom(customHandler) {
|
|
|
37
64
|
};
|
|
38
65
|
}
|
|
39
66
|
const functionHandlerBrand = 'functionHandler';
|
|
67
|
+
/**
|
|
68
|
+
* Use a function created via `defineFunction` to handle the custom query/mutation/subscription. In your function handler,
|
|
69
|
+
* you can use the `Schema["YOUR_QUERY_OR_MUTATION_NAME"]["functionHandler"]` utility type to type the handler function.
|
|
70
|
+
* @example
|
|
71
|
+
* import {
|
|
72
|
+
* type ClientSchema,
|
|
73
|
+
* a,
|
|
74
|
+
* defineData,
|
|
75
|
+
* defineFunction // 1.Import "defineFunction" to create new functions
|
|
76
|
+
* } from '@aws-amplify/backend';
|
|
77
|
+
*
|
|
78
|
+
* // 2. define a function
|
|
79
|
+
* const echoHandler = defineFunction({
|
|
80
|
+
* entry: './echo-handler/handler.ts'
|
|
81
|
+
* })
|
|
82
|
+
*
|
|
83
|
+
* const schema = a.schema({
|
|
84
|
+
* EchoResponse: a.customType({
|
|
85
|
+
* content: a.string(),
|
|
86
|
+
* executionDuration: a.float()
|
|
87
|
+
* }),
|
|
88
|
+
*
|
|
89
|
+
* echo: a
|
|
90
|
+
* .query()
|
|
91
|
+
* .arguments({ content: a.string() })
|
|
92
|
+
* .returns(a.ref('EchoResponse'))
|
|
93
|
+
* .authorization(allow => [allow.publicApiKey()])
|
|
94
|
+
* // 3. set the function has the handler
|
|
95
|
+
* .handler(a.handler.function(echoHandler))
|
|
96
|
+
* });
|
|
97
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}
|
|
98
|
+
* @param fn A function created via `defineFunction`. Alternatively, you can pass in a "string" of the function name and pass
|
|
99
|
+
* in a corresponding value into the `functionMap` property of defineData.
|
|
100
|
+
* @returns A handler for the query / mutation / subscription
|
|
101
|
+
*/
|
|
40
102
|
function fcn(fn) {
|
|
41
103
|
return { [dataSymbol]: fn, ...buildHandler(functionHandlerBrand) };
|
|
42
104
|
}
|
package/dist/cjs/Handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Handler.js","sources":["../../src/Handler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.handler = exports.getHandlerData = void 0;\nconst util_1 = require(\"./util\");\nconst dataSymbol = Symbol('Data');\nfunction buildHandler(brandName) {\n return (0, util_1.brand)(brandName);\n}\nfunction getHandlerData(handler) {\n return handler[dataSymbol];\n}\nexports.getHandlerData = getHandlerData;\n//#region handler.inlineSql\nconst inlineSqlBrand = 'inlineSql';\nfunction inlineSql(sql) {\n return { [dataSymbol]: sql, ...buildHandler(inlineSqlBrand) };\n}\n//#endregion\n//#region handler.sqlReference\nconst sqlReferenceBrand = 'sqlReference';\nfunction sqlReference(sqlFilePath) {\n // used to determine caller directory in order to resolve relative path downstream\n const stack = new Error().stack;\n return {\n [dataSymbol]: { stack, entry: sqlFilePath },\n ...buildHandler(sqlReferenceBrand),\n };\n}\nconst customHandlerBrand = 'customHandler';\nfunction custom(customHandler) {\n // used to determine caller directory in order to resolve relative path downstream\n const stack = new Error().stack;\n return {\n [dataSymbol]: { ...customHandler, stack },\n ...buildHandler(customHandlerBrand),\n };\n}\nconst functionHandlerBrand = 'functionHandler';\nfunction fcn(fn) {\n return { [dataSymbol]: fn, ...buildHandler(functionHandlerBrand) };\n}\n//#endregion\nexports.handler = {\n inlineSql,\n sqlReference,\n custom,\n function: fcn,\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAClC,SAAS,YAAY,CAAC,SAAS,EAAE;AACjC,IAAI,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC;AACD,SAAS,cAAc,CAAC,OAAO,EAAE;AACjC,IAAI,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC;AACD,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"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.handler = exports.getHandlerData = void 0;\nconst util_1 = require(\"./util\");\nconst dataSymbol = Symbol('Data');\nfunction buildHandler(brandName) {\n return (0, util_1.brand)(brandName);\n}\nfunction getHandlerData(handler) {\n return handler[dataSymbol];\n}\nexports.getHandlerData = getHandlerData;\n//#region handler.inlineSql\nconst inlineSqlBrand = 'inlineSql';\nfunction inlineSql(sql) {\n return { [dataSymbol]: sql, ...buildHandler(inlineSqlBrand) };\n}\n//#endregion\n//#region handler.sqlReference\nconst sqlReferenceBrand = 'sqlReference';\nfunction sqlReference(sqlFilePath) {\n // used to determine caller directory in order to resolve relative path downstream\n const stack = new Error().stack;\n return {\n [dataSymbol]: { stack, entry: sqlFilePath },\n ...buildHandler(sqlReferenceBrand),\n };\n}\nconst customHandlerBrand = 'customHandler';\n/**\n * Use a custom JavaScript resolver to handle a query, mutation, or subscription.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/#step-2---configure-custom-business-logic-handler-code}\n * @param customHandler `{ entry: \"path-to-javascript-resolver-file.js\", dataSource: \"Data Source name added via \"backend.data.add*DataSoruce(...)\"}`\n * @returns A JavaScript resolver attached to the query, mutation, or subscription.\n * @example\n * const schema = a.schema({\n * Post: a.model({\n * content: a.string(),\n * likes: a.integer()\n * .authorization(allow => [allow.authenticated().to(['read'])])\n * }).authorization(allow => [\n * allow.owner(),\n * allow.authenticated().to(['read'])\n * ]),\n *\n * likePost: a\n * .mutation()\n * .arguments({ postId: a.id() })\n * .returns(a.ref('Post'))\n * .authorization(allow => [allow.authenticated()])\n * .handler(a.handler.custom({\n * dataSource: a.ref('Post'),\n * entry: './increment-like.js'\n * }))\n * });\n */\nfunction custom(customHandler) {\n // used to determine caller directory in order to resolve relative path downstream\n const stack = new Error().stack;\n return {\n [dataSymbol]: { ...customHandler, stack },\n ...buildHandler(customHandlerBrand),\n };\n}\nconst functionHandlerBrand = 'functionHandler';\n/**\n * Use a function created via `defineFunction` to handle the custom query/mutation/subscription. In your function handler,\n * you can use the `Schema[\"YOUR_QUERY_OR_MUTATION_NAME\"][\"functionHandler\"]` utility type to type the handler function.\n * @example\n * import {\n * type ClientSchema,\n * a,\n * defineData,\n * defineFunction // 1.Import \"defineFunction\" to create new functions\n * } from '@aws-amplify/backend';\n *\n * // 2. define a function\n * const echoHandler = defineFunction({\n * entry: './echo-handler/handler.ts'\n * })\n *\n * const schema = a.schema({\n * EchoResponse: a.customType({\n * content: a.string(),\n * executionDuration: a.float()\n * }),\n *\n * echo: a\n * .query()\n * .arguments({ content: a.string() })\n * .returns(a.ref('EchoResponse'))\n * .authorization(allow => [allow.publicApiKey()])\n * // 3. set the function has the handler\n * .handler(a.handler.function(echoHandler))\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @param fn A function created via `defineFunction`. Alternatively, you can pass in a \"string\" of the function name and pass\n * in a corresponding value into the `functionMap` property of defineData.\n * @returns A handler for the query / mutation / subscription\n */\nfunction fcn(fn) {\n return { [dataSymbol]: fn, ...buildHandler(functionHandlerBrand) };\n}\n//#endregion\nexports.handler = {\n inlineSql,\n sqlReference,\n custom,\n function: fcn,\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAClD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAClC,SAAS,YAAY,CAAC,SAAS,EAAE;AACjC,IAAI,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC;AACD,SAAS,cAAc,CAAC,OAAO,EAAE;AACjC,IAAI,OAAO,OAAO,CAAC,UAAU,CA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,CAAC,EAAE,EAAE;AACjB,IAAI,OAAO,EAAE,CAAC,UAAU,GAAG,EAAE,EAAE,GAAG,YAAY,CAAC,oBAAoB,CAAC,EAAE,CAAC;AACvE,CAAC;AACD;AACA,OAAO,CAAC,OAAO,GAAG;AAClB,IAAI,SAAS;AACb,IAAI,YAAY;AAChB,IAAI,MAAM;AACV,IAAI,QAAQ,EAAE,GAAG;AACjB,CAAC;;"}
|
|
@@ -55,10 +55,28 @@ function _modelRelationalField(type, relatedModel, references) {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* Create
|
|
58
|
+
* Create one-to-one relationship between two models using the `hasOne("MODEL_NAME", "REFERENCE_FIELD(s)")` method.
|
|
59
59
|
* A hasOne relationship always uses a reference to the related model's identifier. Typically this is the `id` field
|
|
60
60
|
* unless overwritten with the `identifier()` method.
|
|
61
|
+
* @example
|
|
62
|
+
* const schema = a.schema({
|
|
63
|
+
* Cart: a.model({
|
|
64
|
+
* items: a.string().required().array(),
|
|
65
|
+
* // 1. Create reference field
|
|
66
|
+
* customerId: a.id(),
|
|
67
|
+
* // 2. Create relationship field with the reference field
|
|
68
|
+
* customer: a.belongsTo('Customer', 'customerId'),
|
|
69
|
+
* }),
|
|
70
|
+
* Customer: a.model({
|
|
71
|
+
* name: a.string(),
|
|
72
|
+
* // 3. Create relationship field with the reference field
|
|
73
|
+
* // from the Cart model
|
|
74
|
+
* activeCart: a.hasOne('Cart', 'customerId')
|
|
75
|
+
* }),
|
|
76
|
+
* });
|
|
77
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship}
|
|
61
78
|
* @param relatedModel the name of the related model
|
|
79
|
+
* @param references the field(s) that should be used to reference the related model
|
|
62
80
|
* @returns a one-to-one relationship definition
|
|
63
81
|
*/
|
|
64
82
|
function hasOne(relatedModel, references) {
|
|
@@ -66,8 +84,29 @@ function hasOne(relatedModel, references) {
|
|
|
66
84
|
}
|
|
67
85
|
exports.hasOne = hasOne;
|
|
68
86
|
/**
|
|
69
|
-
* Create a one-directional one-to-many relationship between two models using the `hasMany()` method.
|
|
87
|
+
* Create a one-directional one-to-many relationship between two models using the `hasMany("MODEL_NAME", "REFERENCE_FIELD(s)")` method.
|
|
88
|
+
* @example
|
|
89
|
+
* const schema = a.schema({
|
|
90
|
+
* Member: a.model({
|
|
91
|
+
* name: a.string().required(),
|
|
92
|
+
* // 1. Create a reference field
|
|
93
|
+
* teamId: a.id(),
|
|
94
|
+
* // 2. Create a belongsTo relationship with the reference field
|
|
95
|
+
* team: a.belongsTo('Team', 'teamId'),
|
|
96
|
+
* })
|
|
97
|
+
* .authorization(allow => [allow.publicApiKey()]),
|
|
98
|
+
*
|
|
99
|
+
* Team: a.model({
|
|
100
|
+
* mantra: a.string().required(),
|
|
101
|
+
* // 3. Create a hasMany relationship with the reference field
|
|
102
|
+
* // from the `Member`s model.
|
|
103
|
+
* members: a.hasMany('Member', 'teamId'),
|
|
104
|
+
* })
|
|
105
|
+
* .authorization(allow => [allow.publicApiKey()]),
|
|
106
|
+
* });
|
|
107
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-one-to-many-relationships}
|
|
70
108
|
* @param relatedModel the name of the related model
|
|
109
|
+
* @param references the field(s) that should be used to reference the related model
|
|
71
110
|
* @returns a one-to-many relationship definition
|
|
72
111
|
*/
|
|
73
112
|
function hasMany(relatedModel, references) {
|
|
@@ -75,10 +114,50 @@ function hasMany(relatedModel, references) {
|
|
|
75
114
|
}
|
|
76
115
|
exports.hasMany = hasMany;
|
|
77
116
|
/**
|
|
78
|
-
*
|
|
117
|
+
* Use `belongsTo()` to create a field to query the related `hasOne()` or `hasMany()` relationship.
|
|
79
118
|
* The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from
|
|
80
119
|
* parent to the related model.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // one-to-many relationship
|
|
123
|
+
* const schema = a.schema({
|
|
124
|
+
* Member: a.model({
|
|
125
|
+
* name: a.string().required(),
|
|
126
|
+
* // 1. Create a reference field
|
|
127
|
+
* teamId: a.id(),
|
|
128
|
+
* // 2. Create a belongsTo relationship with the reference field
|
|
129
|
+
* team: a.belongsTo('Team', 'teamId'),
|
|
130
|
+
* })
|
|
131
|
+
* .authorization(allow => [allow.publicApiKey()]),
|
|
132
|
+
*
|
|
133
|
+
* Team: a.model({
|
|
134
|
+
* mantra: a.string().required(),
|
|
135
|
+
* // 3. Create a hasMany relationship with the reference field
|
|
136
|
+
* // from the `Member`s model.
|
|
137
|
+
* members: a.hasMany('Member', 'teamId'),
|
|
138
|
+
* })
|
|
139
|
+
* .authorization(allow => [allow.publicApiKey()]),
|
|
140
|
+
* });
|
|
141
|
+
* @example
|
|
142
|
+
* // one-to-one relationship
|
|
143
|
+
* const schema = a.schema({
|
|
144
|
+
* Cart: a.model({
|
|
145
|
+
* items: a.string().required().array(),
|
|
146
|
+
* // 1. Create reference field
|
|
147
|
+
* customerId: a.id(),
|
|
148
|
+
* // 2. Create relationship field with the reference field
|
|
149
|
+
* customer: a.belongsTo('Customer', 'customerId'),
|
|
150
|
+
* }),
|
|
151
|
+
* Customer: a.model({
|
|
152
|
+
* name: a.string(),
|
|
153
|
+
* // 3. Create relationship field with the reference field
|
|
154
|
+
* // from the Cart model
|
|
155
|
+
* activeCart: a.hasOne('Cart', 'customerId')
|
|
156
|
+
* }),
|
|
157
|
+
* });
|
|
158
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/}
|
|
81
159
|
* @param relatedModel name of the related `.hasOne()` or `.hasMany()` model
|
|
160
|
+
* @param references the field(s) that should be used to reference the related model
|
|
82
161
|
* @returns a belong-to relationship definition
|
|
83
162
|
*/
|
|
84
163
|
function belongsTo(relatedModel, references) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelRelationalField.js","sources":["../../src/ModelRelationalField.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.belongsTo = exports.hasMany = exports.hasOne = exports.ModelRelationshipTypes = exports.__auth = void 0;\nconst Authorization_1 = require(\"./Authorization\");\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexports.__auth = Symbol('__auth');\nconst brandName = 'modelRelationalField';\nvar ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (exports.ModelRelationshipTypes = ModelRelationshipTypes = {}));\nconst relationalModifiers = [\n 'required',\n 'valueRequired',\n 'authorization',\n];\nconst relationModifierMap = {\n belongsTo: ['authorization'],\n hasMany: ['valueRequired', 'authorization'],\n hasOne: ['required', 'authorization'],\n};\nfunction _modelRelationalField(type, relatedModel, references) {\n const data = {\n relatedModel,\n type,\n fieldType: 'model',\n array: false,\n valueRequired: false,\n arrayRequired: false,\n references,\n authorization: [],\n };\n data.array = type === 'hasMany';\n const relationshipBuilderFunctions = {\n required() {\n data.arrayRequired = true;\n return this;\n },\n valueRequired() {\n data.valueRequired = true;\n return this;\n },\n authorization(callback) {\n const rules = callback(Authorization_1.allow);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n };\n const builder = Object.fromEntries(relationModifierMap[type].map((key) => [\n key,\n relationshipBuilderFunctions[key],\n ]));\n return {\n ...builder,\n data,\n };\n}\n/**\n * Create
|
|
1
|
+
{"version":3,"file":"ModelRelationalField.js","sources":["../../src/ModelRelationalField.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.belongsTo = exports.hasMany = exports.hasOne = exports.ModelRelationshipTypes = exports.__auth = void 0;\nconst Authorization_1 = require(\"./Authorization\");\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexports.__auth = Symbol('__auth');\nconst brandName = 'modelRelationalField';\nvar ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (exports.ModelRelationshipTypes = ModelRelationshipTypes = {}));\nconst relationalModifiers = [\n 'required',\n 'valueRequired',\n 'authorization',\n];\nconst relationModifierMap = {\n belongsTo: ['authorization'],\n hasMany: ['valueRequired', 'authorization'],\n hasOne: ['required', 'authorization'],\n};\nfunction _modelRelationalField(type, relatedModel, references) {\n const data = {\n relatedModel,\n type,\n fieldType: 'model',\n array: false,\n valueRequired: false,\n arrayRequired: false,\n references,\n authorization: [],\n };\n data.array = type === 'hasMany';\n const relationshipBuilderFunctions = {\n required() {\n data.arrayRequired = true;\n return this;\n },\n valueRequired() {\n data.valueRequired = true;\n return this;\n },\n authorization(callback) {\n const rules = callback(Authorization_1.allow);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n };\n const builder = Object.fromEntries(relationModifierMap[type].map((key) => [\n key,\n relationshipBuilderFunctions[key],\n ]));\n return {\n ...builder,\n data,\n };\n}\n/**\n * Create one-to-one relationship between two models using the `hasOne(\"MODEL_NAME\", \"REFERENCE_FIELD(s)\")` method.\n * A hasOne relationship always uses a reference to the related model's identifier. Typically this is the `id` field\n * unless overwritten with the `identifier()` method.\n * @example\n * const schema = a.schema({\n * Cart: a.model({\n * items: a.string().required().array(),\n * // 1. Create reference field\n * customerId: a.id(),\n * // 2. Create relationship field with the reference field\n * customer: a.belongsTo('Customer', 'customerId'),\n * }),\n * Customer: a.model({\n * name: a.string(),\n * // 3. Create relationship field with the reference field\n * // from the Cart model\n * activeCart: a.hasOne('Cart', 'customerId')\n * }),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship}\n * @param relatedModel the name of the related model\n * @param references the field(s) that should be used to reference the related model\n * @returns a one-to-one relationship definition\n */\nfunction hasOne(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.hasOne = hasOne;\n/**\n * Create a one-directional one-to-many relationship between two models using the `hasMany(\"MODEL_NAME\", \"REFERENCE_FIELD(s)\")` method.\n * @example\n * const schema = a.schema({\n * Member: a.model({\n * name: a.string().required(),\n * // 1. Create a reference field\n * teamId: a.id(),\n * // 2. Create a belongsTo relationship with the reference field\n * team: a.belongsTo('Team', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n *\n * Team: a.model({\n * mantra: a.string().required(),\n * // 3. Create a hasMany relationship with the reference field\n * // from the `Member`s model.\n * members: a.hasMany('Member', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-one-to-many-relationships}\n * @param relatedModel the name of the related model\n * @param references the field(s) that should be used to reference the related model\n * @returns a one-to-many relationship definition\n */\nfunction hasMany(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.hasMany = hasMany;\n/**\n * Use `belongsTo()` to create a field to query the related `hasOne()` or `hasMany()` relationship.\n * The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from\n * parent to the related model.\n *\n * @example\n * // one-to-many relationship\n * const schema = a.schema({\n * Member: a.model({\n * name: a.string().required(),\n * // 1. Create a reference field\n * teamId: a.id(),\n * // 2. Create a belongsTo relationship with the reference field\n * team: a.belongsTo('Team', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n *\n * Team: a.model({\n * mantra: a.string().required(),\n * // 3. Create a hasMany relationship with the reference field\n * // from the `Member`s model.\n * members: a.hasMany('Member', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n * });\n * @example\n * // one-to-one relationship\n * const schema = a.schema({\n * Cart: a.model({\n * items: a.string().required().array(),\n * // 1. Create reference field\n * customerId: a.id(),\n * // 2. Create relationship field with the reference field\n * customer: a.belongsTo('Customer', 'customerId'),\n * }),\n * Customer: a.model({\n * name: a.string(),\n * // 3. Create relationship field with the reference field\n * // from the Cart model\n * activeCart: a.hasOne('Cart', 'customerId')\n * }),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/}\n * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model\n * @param references the field(s) that should be used to reference the related model\n * @returns a belong-to relationship definition\n */\nfunction belongsTo(relatedModel, references) {\n return _modelRelationalField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.belongsTo = belongsTo;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AAChH,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnD;AACA;AACA;AACA,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAElC,IAAI,sBAAsB,CAAC;AAC3B,CAAC,UAAU,sBAAsB,EAAE;AACnC,IAAI,sBAAsB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AAChD,IAAI,sBAAsB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAClD,IAAI,sBAAsB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;AACtD,CAAC,EAAE,sBAAsB,KAAK,OAAO,CAAC,sBAAsB,GAAG,sBAAsB,GAAG,EAAE,CAAC,CAAC,CAAC;AAM7F,MAAM,mBAA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AAC9E,QAAQ,GAAG;AACX,QAAQ,4BAA4B,CAAC,GAAG,CAAC;AACzC,KAAK,CAAC,CAAC,CAAC;AACR,IAAI,OAAO;AACX,QAAQ,GAAG,OAAO;AAClB,QAAQ,IAAI;AACZ,KAAK,CAAC;AACN,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,MAAM,CAAC,YAAY,EAAE,UAAU,EAAE;AAC1C,IAAI,OAAO,qBAAqB,CAAC,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACrI,CAAC;AACD,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;AACxB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,OAAO,CAAC,YAAY,EAAE,UAAU,EAAE;AAC3C,IAAI,OAAO,qBAAqB,CAAC,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACtI,CAAC;AACD,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,SAAS,CAAC,YAAY,EAAE,UAAU,EAAE;AAC7C,IAAI,OAAO,qBAAqB,CAAC,sBAAsB,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AACxI,CAAC;AACD,OAAO,CAAC,SAAS,GAAG,SAAS;;"}
|
|
@@ -55,6 +55,26 @@ export type InternalCustom<B extends CustomOperationBrand = any> = CustomOperati
|
|
|
55
55
|
data: InternalCustomData;
|
|
56
56
|
};
|
|
57
57
|
export type QueryCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof queryBrand>;
|
|
58
|
+
/**
|
|
59
|
+
* Use a custom query to define an API request that will retrieve backend data.
|
|
60
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}
|
|
61
|
+
* @example
|
|
62
|
+
* const schema = a.schema({
|
|
63
|
+
* echo: a
|
|
64
|
+
* .query()
|
|
65
|
+
* .arguments({ content: a.string() })
|
|
66
|
+
* .returns(a.ref('EchoResponse'))
|
|
67
|
+
* .authorization(allow => [allow.publicApiKey()])
|
|
68
|
+
* // 3. set the function has the handler
|
|
69
|
+
* .handler(a.handler.function(echoHandler)),
|
|
70
|
+
*
|
|
71
|
+
* EchoResponse: a.customType({
|
|
72
|
+
* content: a.string(),
|
|
73
|
+
* executionDuration: a.float()
|
|
74
|
+
* }),
|
|
75
|
+
* });
|
|
76
|
+
* @returns a custom query
|
|
77
|
+
*/
|
|
58
78
|
export declare function query(): CustomOperation<{
|
|
59
79
|
arguments: null;
|
|
60
80
|
returnType: null;
|
|
@@ -63,6 +83,18 @@ export declare function query(): CustomOperation<{
|
|
|
63
83
|
handlers: null;
|
|
64
84
|
}, 'for', typeof queryBrand>;
|
|
65
85
|
export type MutationCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof mutationBrand>;
|
|
86
|
+
/**
|
|
87
|
+
* Use a custom mutation to define an API request that will modify backend data or trigger a subscription event.
|
|
88
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}
|
|
89
|
+
* @example
|
|
90
|
+
* likePost: a
|
|
91
|
+
* .mutation()
|
|
92
|
+
* .arguments({ postId: a.string() })
|
|
93
|
+
* .returns(a.ref('Post'))
|
|
94
|
+
* .authorization(allow => [allow.publicApiKey()])
|
|
95
|
+
* .handler(a.handler.function(echoHandler))
|
|
96
|
+
* @returns a custom mutation
|
|
97
|
+
*/
|
|
66
98
|
export declare function mutation(): CustomOperation<{
|
|
67
99
|
arguments: null;
|
|
68
100
|
returnType: null;
|
|
@@ -71,6 +103,20 @@ export declare function mutation(): CustomOperation<{
|
|
|
71
103
|
handlers: null;
|
|
72
104
|
}, 'for', typeof mutationBrand>;
|
|
73
105
|
export type SubscriptionCustomOperation = CustomOperation<CustomOperationParamShape, any, typeof subscriptionBrand>;
|
|
106
|
+
/**
|
|
107
|
+
* Define a custom subscription to receive an event when a mutation is triggered
|
|
108
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-subscription/}
|
|
109
|
+
* @example
|
|
110
|
+
* // Subscribe to incoming messages
|
|
111
|
+
* receive: a.subscription()
|
|
112
|
+
* // subscribes to the 'publish' mutation
|
|
113
|
+
* .for(a.ref('publish'))
|
|
114
|
+
* // subscription handler to set custom filters
|
|
115
|
+
* .handler(a.handler.custom({entry: './receive.js'}))
|
|
116
|
+
* // authorization rules as to who can subscribe to the data
|
|
117
|
+
* .authorization(allow => [allow.publicApiKey()]),
|
|
118
|
+
* @returns a custom subscription
|
|
119
|
+
*/
|
|
74
120
|
export declare function subscription(): CustomOperation<{
|
|
75
121
|
arguments: null;
|
|
76
122
|
returnType: null;
|
|
@@ -48,12 +48,58 @@ function _custom(typeName, brand) {
|
|
|
48
48
|
}, brand);
|
|
49
49
|
return { ...builder, data };
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Use a custom query to define an API request that will retrieve backend data.
|
|
53
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}
|
|
54
|
+
* @example
|
|
55
|
+
* const schema = a.schema({
|
|
56
|
+
* echo: a
|
|
57
|
+
* .query()
|
|
58
|
+
* .arguments({ content: a.string() })
|
|
59
|
+
* .returns(a.ref('EchoResponse'))
|
|
60
|
+
* .authorization(allow => [allow.publicApiKey()])
|
|
61
|
+
* // 3. set the function has the handler
|
|
62
|
+
* .handler(a.handler.function(echoHandler)),
|
|
63
|
+
*
|
|
64
|
+
* EchoResponse: a.customType({
|
|
65
|
+
* content: a.string(),
|
|
66
|
+
* executionDuration: a.float()
|
|
67
|
+
* }),
|
|
68
|
+
* });
|
|
69
|
+
* @returns a custom query
|
|
70
|
+
*/
|
|
51
71
|
function query() {
|
|
52
72
|
return _custom('Query', queryBrand);
|
|
53
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Use a custom mutation to define an API request that will modify backend data or trigger a subscription event.
|
|
76
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}
|
|
77
|
+
* @example
|
|
78
|
+
* likePost: a
|
|
79
|
+
* .mutation()
|
|
80
|
+
* .arguments({ postId: a.string() })
|
|
81
|
+
* .returns(a.ref('Post'))
|
|
82
|
+
* .authorization(allow => [allow.publicApiKey()])
|
|
83
|
+
* .handler(a.handler.function(echoHandler))
|
|
84
|
+
* @returns a custom mutation
|
|
85
|
+
*/
|
|
54
86
|
function mutation() {
|
|
55
87
|
return _custom('Mutation', mutationBrand);
|
|
56
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Define a custom subscription to receive an event when a mutation is triggered
|
|
91
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-subscription/}
|
|
92
|
+
* @example
|
|
93
|
+
* // Subscribe to incoming messages
|
|
94
|
+
* receive: a.subscription()
|
|
95
|
+
* // subscribes to the 'publish' mutation
|
|
96
|
+
* .for(a.ref('publish'))
|
|
97
|
+
* // subscription handler to set custom filters
|
|
98
|
+
* .handler(a.handler.custom({entry: './receive.js'}))
|
|
99
|
+
* // authorization rules as to who can subscribe to the data
|
|
100
|
+
* .authorization(allow => [allow.publicApiKey()]),
|
|
101
|
+
* @returns a custom subscription
|
|
102
|
+
*/
|
|
57
103
|
function subscription() {
|
|
58
104
|
return _custom('Subscription', subscriptionBrand);
|
|
59
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomOperation.mjs","sources":["../../src/CustomOperation.ts"],"sourcesContent":["import { brand } from './util';\nimport { allowForCustomOperations, } from './Authorization';\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nexport const CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...brand(brandValue) };\n}\nfunction _custom(typeName, brand) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n };\n const builder = brandedBuilder({\n arguments(args) {\n data.arguments = args;\n return this;\n },\n returns(returnType) {\n data.returnType = returnType;\n return this;\n },\n authorization(callback) {\n const rules = callback(allowForCustomOperations);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n handler(handlers) {\n data.handlers = Array.isArray(handlers)\n ? handlers\n : [handlers];\n return this;\n },\n for(source) {\n data.subscriptionSource = Array.isArray(source) ? source : [source];\n return this;\n },\n }, brand);\n return { ...builder, data };\n}\nexport function query() {\n return _custom('Query', queryBrand);\n}\nexport function mutation() {\n return _custom('Mutation', mutationBrand);\n}\nexport function subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAC1C,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAChD,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAC5C,MAAC,oBAAoB,GAAG;AACpC,IAAI,OAAO;AACX,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,EAAE;AACF,SAAS,cA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;AACpB,YAAY,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC;AAChF,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS;AACT,KAAK,EAAE,KAAK,CAAC,CAAC;AACd,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;
|
|
1
|
+
{"version":3,"file":"CustomOperation.mjs","sources":["../../src/CustomOperation.ts"],"sourcesContent":["import { brand } from './util';\nimport { allowForCustomOperations, } from './Authorization';\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nexport const CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...brand(brandValue) };\n}\nfunction _custom(typeName, brand) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n };\n const builder = brandedBuilder({\n arguments(args) {\n data.arguments = args;\n return this;\n },\n returns(returnType) {\n data.returnType = returnType;\n return this;\n },\n authorization(callback) {\n const rules = callback(allowForCustomOperations);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n handler(handlers) {\n data.handlers = Array.isArray(handlers)\n ? handlers\n : [handlers];\n return this;\n },\n for(source) {\n data.subscriptionSource = Array.isArray(source) ? source : [source];\n return this;\n },\n }, brand);\n return { ...builder, data };\n}\n/**\n * Use a custom query to define an API request that will retrieve backend data.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * const schema = a.schema({\n * echo: a\n * .query()\n * .arguments({ content: a.string() })\n * .returns(a.ref('EchoResponse'))\n * .authorization(allow => [allow.publicApiKey()])\n * // 3. set the function has the handler\n * .handler(a.handler.function(echoHandler)),\n *\n * EchoResponse: a.customType({\n * content: a.string(),\n * executionDuration: a.float()\n * }),\n * });\n * @returns a custom query\n */\nexport function query() {\n return _custom('Query', queryBrand);\n}\n/**\n * Use a custom mutation to define an API request that will modify backend data or trigger a subscription event.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/}\n * @example\n * likePost: a\n * .mutation()\n * .arguments({ postId: a.string() })\n * .returns(a.ref('Post'))\n * .authorization(allow => [allow.publicApiKey()])\n * .handler(a.handler.function(echoHandler))\n * @returns a custom mutation\n */\nexport function mutation() {\n return _custom('Mutation', mutationBrand);\n}\n/**\n * Define a custom subscription to receive an event when a mutation is triggered\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/custom-subscription/}\n * @example\n * // Subscribe to incoming messages\n * receive: a.subscription()\n * // subscribes to the 'publish' mutation\n * .for(a.ref('publish'))\n * // subscription handler to set custom filters\n * .handler(a.handler.custom({entry: './receive.js'}))\n * // authorization rules as to who can subscribe to the data\n * .authorization(allow => [allow.publicApiKey()]),\n * @returns a custom subscription\n */\nexport function subscription() {\n return _custom('Subscription', subscriptionBrand);\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAC1C,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAChD,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAC5C,MAAC,oBAAoB,GAAG;AACpC,IAAI,OAAO;AACX,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,EAAE;AACF,SAAS,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;AAC7C,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;AAChD,CAAC;AACD,SAAS,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE;AAClC,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,IAAI;AACxB,QAAQ,aAAa,EAAE,EAAE;AACzB,QAAQ,QAAQ,EAA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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,GAAG;AACxB,IAAI,OAAO,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,QAAQ,GAAG;AAC3B,IAAI,OAAO,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAC9C,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,YAAY,GAAG;AAC/B,IAAI,OAAO,OAAO,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;AACtD;;;;"}
|
package/dist/esm/CustomType.d.ts
CHANGED
|
@@ -29,6 +29,38 @@ export type CustomType<T extends CustomTypeParamShape> = T & Brand<'customType'>
|
|
|
29
29
|
export type InternalCustomType = CustomType<any> & {
|
|
30
30
|
data: InternalCustomTypeData;
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Define a custom type. This type represents an inline, typed JSON object.
|
|
34
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/add-fields/#specify-a-custom-field-type}
|
|
35
|
+
* @param fields the fields to be added to the custom type
|
|
36
|
+
* @returns a custom type
|
|
37
|
+
* @example
|
|
38
|
+
* a.schema({
|
|
39
|
+
* Post: a.model({
|
|
40
|
+
* location: a.customType({
|
|
41
|
+
* lat: a.float(),
|
|
42
|
+
* long: a.float(),
|
|
43
|
+
* }),
|
|
44
|
+
* content: a.string(),
|
|
45
|
+
* }),
|
|
46
|
+
* });
|
|
47
|
+
* @example
|
|
48
|
+
* a.schema({
|
|
49
|
+
* Location: a.customType({
|
|
50
|
+
* lat: a.float(),
|
|
51
|
+
* long: a.float(),
|
|
52
|
+
* }),
|
|
53
|
+
*
|
|
54
|
+
* Post: a.model({
|
|
55
|
+
* location: a.ref('Location'),
|
|
56
|
+
* content: a.string(),
|
|
57
|
+
* }),
|
|
58
|
+
*
|
|
59
|
+
* User: a.model({
|
|
60
|
+
* lastKnownLocation: a.ref('Location'),
|
|
61
|
+
* }),
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
32
64
|
export declare function customType<T extends CustomTypeFields>(fields: T): CustomType<{
|
|
33
65
|
fields: T;
|
|
34
66
|
}>;
|
package/dist/esm/CustomType.mjs
CHANGED
|
@@ -5,6 +5,38 @@ function _customType(fields) {
|
|
|
5
5
|
};
|
|
6
6
|
return { data };
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Define a custom type. This type represents an inline, typed JSON object.
|
|
10
|
+
* @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/add-fields/#specify-a-custom-field-type}
|
|
11
|
+
* @param fields the fields to be added to the custom type
|
|
12
|
+
* @returns a custom type
|
|
13
|
+
* @example
|
|
14
|
+
* a.schema({
|
|
15
|
+
* Post: a.model({
|
|
16
|
+
* location: a.customType({
|
|
17
|
+
* lat: a.float(),
|
|
18
|
+
* long: a.float(),
|
|
19
|
+
* }),
|
|
20
|
+
* content: a.string(),
|
|
21
|
+
* }),
|
|
22
|
+
* });
|
|
23
|
+
* @example
|
|
24
|
+
* a.schema({
|
|
25
|
+
* Location: a.customType({
|
|
26
|
+
* lat: a.float(),
|
|
27
|
+
* long: a.float(),
|
|
28
|
+
* }),
|
|
29
|
+
*
|
|
30
|
+
* Post: a.model({
|
|
31
|
+
* location: a.ref('Location'),
|
|
32
|
+
* content: a.string(),
|
|
33
|
+
* }),
|
|
34
|
+
*
|
|
35
|
+
* User: a.model({
|
|
36
|
+
* lastKnownLocation: a.ref('Location'),
|
|
37
|
+
* }),
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
8
40
|
function customType(fields) {
|
|
9
41
|
return _customType(fields);
|
|
10
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomType.mjs","sources":["../../src/CustomType.ts"],"sourcesContent":["function _customType(fields) {\n const data = {\n fields,\n type: 'customType',\n };\n return { data };\n}\nexport function customType(fields) {\n return _customType(fields);\n}\n"],"names":[],"mappings":"AAAA,SAAS,WAAW,CAAC,MAAM,EAAE;AAC7B,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,IAAI,EAAE,YAAY;AAC1B,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;AACpB,CAAC;
|
|
1
|
+
{"version":3,"file":"CustomType.mjs","sources":["../../src/CustomType.ts"],"sourcesContent":["function _customType(fields) {\n const data = {\n fields,\n type: 'customType',\n };\n return { data };\n}\n/**\n * Define a custom type. This type represents an inline, typed JSON object.\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/add-fields/#specify-a-custom-field-type}\n * @param fields the fields to be added to the custom type\n * @returns a custom type\n * @example\n * a.schema({\n * Post: a.model({\n * location: a.customType({\n * lat: a.float(),\n * long: a.float(),\n * }),\n * content: a.string(),\n * }),\n * });\n * @example\n * a.schema({\n * Location: a.customType({\n * lat: a.float(),\n * long: a.float(),\n * }),\n *\n * Post: a.model({\n * location: a.ref('Location'),\n * content: a.string(),\n * }),\n *\n * User: a.model({\n * lastKnownLocation: a.ref('Location'),\n * }),\n * });\n */\nexport function customType(fields) {\n return _customType(fields);\n}\n"],"names":[],"mappings":"AAAA,SAAS,WAAW,CAAC,MAAM,EAAE;AAC7B,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM;AACd,QAAQ,IAAI,EAAE,YAAY;AAC1B,KAAK,CAAC;AACN,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;AACpB,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU,CAAC,MAAM,EAAE;AACnC,IAAI,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC/B;;;;"}
|