@aws-amplify/data-schema 1.19.0 → 1.20.0
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/Authorization.js.map +1 -1
- package/dist/cjs/ClientSchema/utilities/index.js.map +1 -1
- package/dist/cjs/CombineSchema.js +2 -2
- package/dist/cjs/CombineSchema.js.map +1 -1
- package/dist/cjs/CustomOperation.js +5 -5
- package/dist/cjs/CustomOperation.js.map +1 -1
- package/dist/cjs/CustomType.js +1 -2
- package/dist/cjs/CustomType.js.map +1 -1
- package/dist/cjs/EnumType.js +1 -2
- package/dist/cjs/EnumType.js.map +1 -1
- package/dist/cjs/Handler.js +2 -2
- package/dist/cjs/Handler.js.map +1 -1
- package/dist/cjs/ModelField.js +24 -17
- package/dist/cjs/ModelField.js.map +1 -1
- package/dist/cjs/ModelIndex.js +1 -2
- package/dist/cjs/ModelIndex.js.map +1 -1
- package/dist/cjs/ModelRelationshipField.js +4 -4
- package/dist/cjs/ModelRelationshipField.js.map +1 -1
- package/dist/cjs/ModelSchema.js +3 -3
- package/dist/cjs/ModelSchema.js.map +1 -1
- package/dist/cjs/ModelType.js +2 -2
- package/dist/cjs/ModelType.js.map +1 -1
- package/dist/cjs/RefType.js +1 -2
- package/dist/cjs/RefType.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +12 -3
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/Validate.js +145 -0
- package/dist/cjs/Validate.js.map +1 -0
- package/dist/cjs/a.js.map +1 -1
- package/dist/cjs/ai/ConversationSchemaGraphQLTypes.js.map +1 -1
- package/dist/cjs/ai/ConversationSchemaProcessor.js.map +1 -1
- package/dist/cjs/ai/ConversationType.js +3 -3
- package/dist/cjs/ai/ConversationType.js.map +1 -1
- package/dist/cjs/ai/ModelType.js +1 -2
- package/dist/cjs/ai/ModelType.js.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/cjs/runtime/addSchemaToClient.js +1 -2
- package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
- package/dist/cjs/runtime/addSchemaToClientWithInstance.js +1 -2
- package/dist/cjs/runtime/addSchemaToClientWithInstance.js.map +1 -1
- package/dist/cjs/runtime/bridge-types.js.map +1 -1
- package/dist/cjs/runtime/client/index.js.map +1 -1
- package/dist/cjs/runtime/client/index.v3.js.map +1 -1
- package/dist/cjs/runtime/index.js.map +1 -1
- package/dist/cjs/runtime/index.v3.js.map +1 -1
- package/dist/cjs/runtime/internals/APIClient.js +10 -10
- package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/conversationStreamEventDeserializers.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/convertItemToConversation.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createDeleteConversationFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createOnStreamEventFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/createUpdateConversationFunction.js.map +1 -1
- package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js +2 -2
- package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js.map +1 -1
- package/dist/cjs/runtime/internals/cancellation.js +2 -3
- package/dist/cjs/runtime/internals/cancellation.js.map +1 -1
- package/dist/cjs/runtime/internals/clientUtils.js.map +1 -1
- package/dist/cjs/runtime/internals/generateCustomOperationsProperty.js +4 -5
- package/dist/cjs/runtime/internals/generateCustomOperationsProperty.js.map +1 -1
- package/dist/cjs/runtime/internals/index.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/custom.js +1 -2
- package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/get.js +1 -2
- package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/indexQuery.js +1 -2
- package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/list.js +1 -2
- package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/observeQuery.js +1 -2
- package/dist/cjs/runtime/internals/operations/observeQuery.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/subscription.js +1 -2
- package/dist/cjs/runtime/internals/operations/subscription.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/utils.js +2 -3
- package/dist/cjs/runtime/internals/operations/utils.js.map +1 -1
- package/dist/cjs/runtime/internals/server/generateModelsProperty.js +1 -2
- package/dist/cjs/runtime/internals/server/generateModelsProperty.js.map +1 -1
- package/dist/cjs/runtime/internals/server/index.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +1 -2
- package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateEnumsProperty.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js +1 -2
- package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js +1 -2
- package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js +1 -2
- package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js +1 -2
- package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js +1 -2
- package/dist/cjs/runtime/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.js.map +1 -1
- package/dist/cjs/runtime/utils/findIndexByFields.js +1 -2
- package/dist/cjs/runtime/utils/findIndexByFields.js.map +1 -1
- package/dist/cjs/runtime/utils/index.js.map +1 -1
- package/dist/cjs/runtime/utils/resolveOwnerFields.js +1 -2
- package/dist/cjs/runtime/utils/resolveOwnerFields.js.map +1 -1
- package/dist/cjs/runtime/utils/resolvePKFields.js +1 -2
- package/dist/cjs/runtime/utils/resolvePKFields.js.map +1 -1
- package/dist/cjs/runtime/utils/selfAwareAsync.js +1 -2
- package/dist/cjs/runtime/utils/selfAwareAsync.js.map +1 -1
- package/dist/cjs/runtime/utils/stringTransformation.js +1 -2
- package/dist/cjs/runtime/utils/stringTransformation.js.map +1 -1
- package/dist/cjs/util/Brand.js +3 -3
- package/dist/cjs/util/Brand.js.map +1 -1
- package/dist/cjs/util/index.js.map +1 -1
- package/dist/esm/Authorization.d.ts +8 -8
- package/dist/esm/Authorization.mjs.map +1 -1
- package/dist/esm/CombineSchema.mjs.map +1 -1
- package/dist/esm/CustomOperation.mjs.map +1 -1
- package/dist/esm/CustomType.mjs.map +1 -1
- package/dist/esm/EnumType.mjs.map +1 -1
- package/dist/esm/Handler.mjs.map +1 -1
- package/dist/esm/ModelField.d.ts +39 -24
- package/dist/esm/ModelField.mjs +9 -2
- package/dist/esm/ModelField.mjs.map +1 -1
- package/dist/esm/ModelIndex.mjs.map +1 -1
- package/dist/esm/ModelRelationshipField.mjs.map +1 -1
- package/dist/esm/ModelSchema.mjs.map +1 -1
- package/dist/esm/ModelType.d.ts +1 -1
- package/dist/esm/ModelType.mjs.map +1 -1
- package/dist/esm/RefType.mjs.map +1 -1
- package/dist/esm/SchemaProcessor.mjs +12 -2
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/Validate.d.ts +218 -0
- package/dist/esm/Validate.mjs +142 -0
- package/dist/esm/Validate.mjs.map +1 -0
- package/dist/esm/ai/ConversationSchemaGraphQLTypes.mjs.map +1 -1
- package/dist/esm/ai/ConversationSchemaProcessor.mjs.map +1 -1
- package/dist/esm/ai/ConversationType.mjs.map +1 -1
- package/dist/esm/ai/ModelType.mjs.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
- package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
- package/dist/esm/runtime/bridge-types.mjs.map +1 -1
- package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/conversationStreamEventDeserializers.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createCreateConversationFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createDeleteConversationFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createDeleteConversationFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createGetConversationFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createListConversationsFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createListMessagesFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createOnStreamEventFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createOnStreamEventFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createSendMessageFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs +1 -1
- package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.d.ts +1 -1
- package/dist/esm/runtime/internals/ai/createUpdateConversationFunction.mjs.map +1 -1
- package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs.map +1 -1
- package/dist/esm/runtime/internals/cancellation.mjs.map +1 -1
- package/dist/esm/runtime/internals/clientUtils.mjs.map +1 -1
- package/dist/esm/runtime/internals/generateCustomOperationsProperty.d.ts +3 -3
- package/dist/esm/runtime/internals/generateCustomOperationsProperty.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/indexQuery.mjs +1 -1
- package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/observeQuery.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/subscription.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/utils.mjs.map +1 -1
- package/dist/esm/runtime/internals/server/generateModelsProperty.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateEnumsProperty.d.ts +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateEnumsProperty.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/runtimeTypeGuards/isGraphQLResponseWithErrors.mjs.map +1 -1
- package/dist/esm/runtime/utils/findIndexByFields.mjs.map +1 -1
- package/dist/esm/runtime/utils/resolveOwnerFields.mjs.map +1 -1
- package/dist/esm/runtime/utils/resolvePKFields.mjs.map +1 -1
- package/dist/esm/runtime/utils/selfAwareAsync.mjs.map +1 -1
- package/dist/esm/runtime/utils/stringTransformation.mjs.map +1 -1
- package/dist/esm/util/Brand.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/ModelField.ts +70 -29
- package/src/SchemaProcessor.ts +12 -0
- package/src/Validate.ts +418 -0
- package/src/index.ts +1 -1
|
@@ -174,7 +174,7 @@ export declare const allow: {
|
|
|
174
174
|
* @param provider the authentication provider - supports "userPools", "identityPool", or "oidc"
|
|
175
175
|
* @returns an authorization rule for authenticated users
|
|
176
176
|
*/
|
|
177
|
-
readonly ownersDefinedIn: <
|
|
177
|
+
readonly ownersDefinedIn: <T extends string>(ownersField: T, provider?: OwnerProviders) => Authorization<"owner", T, true> & {
|
|
178
178
|
to: typeof to;
|
|
179
179
|
identityClaim: typeof identityClaim;
|
|
180
180
|
};
|
|
@@ -222,7 +222,7 @@ export declare const allow: {
|
|
|
222
222
|
* @param provider the authentication provider - supports "userPools" or "oidc"
|
|
223
223
|
* @returns an authorization rule to grant access by a specific group
|
|
224
224
|
*/
|
|
225
|
-
readonly groupDefinedIn: <
|
|
225
|
+
readonly groupDefinedIn: <T extends string>(groupsField: T, provider?: GroupProvider) => Authorization<"groups", T, false> & {
|
|
226
226
|
to: typeof to;
|
|
227
227
|
withClaimIn: typeof withClaimIn;
|
|
228
228
|
};
|
|
@@ -238,7 +238,7 @@ export declare const allow: {
|
|
|
238
238
|
* @param provider the authentication provider - supports "userPools" or "oidc"
|
|
239
239
|
* @returns an authorization rule to grant access by a specific group
|
|
240
240
|
*/
|
|
241
|
-
readonly groupsDefinedIn: <
|
|
241
|
+
readonly groupsDefinedIn: <T extends string>(groupsField: T, provider?: GroupProvider) => Authorization<"groups", T, true> & {
|
|
242
242
|
to: typeof to;
|
|
243
243
|
withClaimIn: typeof withClaimIn;
|
|
244
244
|
};
|
|
@@ -363,13 +363,13 @@ export type ImpliedAuthField<T extends Authorization<any, any, any>> = T extends
|
|
|
363
363
|
export type ImpliedAuthFields<T extends Authorization<any, any, any>> = ImpliedAuthField<T> extends never ? never : UnionToIntersection<ImpliedAuthField<T>>;
|
|
364
364
|
export declare const accessData: <T extends Authorization<any, any, any>>(authorization: T) => {
|
|
365
365
|
strategy?: any;
|
|
366
|
-
provider?:
|
|
367
|
-
operations?:
|
|
366
|
+
provider?: Provider;
|
|
367
|
+
operations?: Operation[];
|
|
368
368
|
groupOrOwnerField?: any;
|
|
369
|
-
groups?: string[]
|
|
369
|
+
groups?: string[];
|
|
370
370
|
multiOwner: any;
|
|
371
|
-
identityClaim?: string
|
|
372
|
-
groupClaim?: string
|
|
371
|
+
identityClaim?: string;
|
|
372
|
+
groupClaim?: string;
|
|
373
373
|
};
|
|
374
374
|
export declare const accessSchemaData: <T extends SchemaAuthorization<any, any, any>>(authorization: T) => T[typeof __data];
|
|
375
375
|
export type AllowModifier = typeof allow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Authorization.mjs","sources":["../../src/Authorization.ts"],"sourcesContent":["const __data = Symbol('data');\n/**\n * All possible providers.\n *\n * This list should not be used if you need to restrict available providers\n * according to an auth strategcy. E.g., `public` auth can only be facilitated\n * by `apiKey` and `identityPool` providers.\n */\nexport const Providers = [\n 'apiKey',\n 'identityPool',\n 'userPools',\n 'oidc',\n 'function',\n];\n/**\n * The subset of auth providers that can facilitate `public` auth.\n */\nexport const PublicProviders = ['apiKey', 'identityPool'];\n/**\n * The subset of auth providers that can facilitate `private` auth.\n */\nexport const PrivateProviders = ['userPools', 'oidc', 'identityPool'];\n/**\n * The subset of auth providers that can facilitate `owner` auth.\n */\nexport const OwnerProviders = ['userPools', 'oidc'];\n/**\n * The subset of auth providers that can facilitate `group` auth.\n */\nexport const GroupProviders = ['userPools', 'oidc'];\n/**\n * The subset of auth providers that can facilitate `custom` auth.\n */\nexport const CustomProviders = ['function'];\nexport const Strategies = [\n 'public',\n 'private',\n 'owner',\n 'groups',\n 'custom',\n];\n/**\n * The operations that can be performed against an API.\n */\nexport const Operations = [\n 'create',\n 'update',\n 'delete',\n 'read',\n 'get',\n 'list',\n 'sync',\n 'listen',\n 'search',\n];\n/**\n * The operations that can be performed against an API by a Lambda function.\n */\nexport const ResourceOperations = ['query', 'mutate', 'listen'];\n/**\n * Creates a shallow copy of an object with an individual field pruned away.\n *\n * @param original The original object to prune.\n * @param without The field to prune.\n * @returns The pruned object.\n */\nfunction omit(original, without) {\n const pruned = { ...original };\n delete pruned[without];\n return pruned;\n}\nfunction to(operations) {\n this[__data].operations = operations;\n return omit(this, 'to');\n}\n/**\n * Specifies a property of the identity JWT to use in place of `sub::username`\n * as the value to match against the owner field for authorization.\n *\n * @param this Authorization object to operate against.\n * @param property A property of identity JWT.\n * @returns A copy of the Authorization object with the claim attached.\n */\nfunction identityClaim(property) {\n this[__data].identityClaim = property;\n return omit(this, 'identityClaim');\n}\nfunction withClaimIn(property) {\n this[__data].groupClaim = property;\n return omit(this, 'withClaimIn');\n}\nfunction validateProvider(needle, haystack) {\n if (needle && !haystack.includes(needle)) {\n throw new Error(`Invalid provider (${needle}) given!`);\n }\n}\nfunction authData(defaults, builderMethods) {\n return {\n [__data]: {\n strategy: 'public',\n provider: undefined,\n operations: undefined,\n groupOrOwnerField: undefined,\n multiOwner: false,\n identityClaim: undefined,\n groups: undefined,\n ...defaults,\n },\n ...builderMethods,\n };\n}\n/**\n * Defines an authorization rule for your data models and fields. First choose an authorization strategy (`public`,\n * `private`, `owner`, `group`, or `custom`), then choose an auth provider (`apiKey`, `identitypool`, `userPools`, `oidc`, or `function`)\n * and optionally use `.to(...)` to specify the operations that can be performed against your data models and fields.\n */\nexport const allow = {\n /**\n * Authorize unauthenticated users by using API key based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n publicApiKey() {\n return authData({\n strategy: 'public',\n provider: 'apiKey',\n }, {\n to,\n });\n },\n /**\n * Authorize unauthenticated users by using IDENTITYPOOL based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n guest() {\n return authData({\n strategy: 'public',\n provider: 'identityPool',\n }, {\n to,\n });\n },\n /**\n * Authorize authenticated users. By default, `.authenticated()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.authenticated(\"identityPool\")` or `.authenticated(\"oidc\")` to use identityPool or OIDC based authorization for authenticated users.\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n authenticated(provider) {\n validateProvider(provider, PrivateProviders);\n return authData({\n strategy: 'private',\n provider,\n }, {\n to,\n });\n },\n /**\n * Authorize access on a per-user (owner) basis. By setting owner-based authorization, a new `owner: a.string()`\n * field will be added to the model to store which user \"owns\" the item. Upon item creation, the \"owner field\" is\n * auto-populated with the authenticated user's information. If you want to specify which field should be used as\n * the owner field, you can use the `ownerDefinedIn` builder function instead.\n *\n * By default, `.owner()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.owner(\"oidc\")` to use OIDC based authentication to designate the owner.\n *\n * To change the specific claim that should be used as the user identifier within the owner field, chain the\n * `.identityClaim(...)` method.\n *\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n owner(provider) {\n validateProvider(provider, OwnerProviders);\n return authData({\n strategy: 'owner',\n provider,\n groupOrOwnerField: 'owner',\n }, {\n to,\n identityClaim,\n });\n },\n /**\n * Authorize access on a per-user (owner) basis with specifying which field should be used as the owner field.\n *\n * By default, `.owner()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.ownerDefinedIn(\"owner\", \"oidc\")` to use OIDC based authentication to designate the owner.\n *\n * To change the specific claim that should be used as the user identifier within the owner field, chain the\n * `.identityClaim(...)` method.\n *\n * @param ownerField the field that contains the owner information\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n ownerDefinedIn(ownerField, provider) {\n validateProvider(provider, OwnerProviders);\n return authData({\n strategy: 'owner',\n provider,\n groupOrOwnerField: ownerField,\n }, {\n to,\n identityClaim,\n });\n },\n /**\n * Authorize access for multi-user / multi-owner access. By setting multi-owner-based authorization, a new `owners: a.string().array()`\n * field will be added to the model to store which users \"own\" the item. Upon item creation, the \"owners field\" is\n * auto-populated with the authenticated user's information. To grant other users access to the item, append their user identifier into the `owners` array.\n *\n * You can specify which field should be used as the owners field by passing the `ownersField` parameter.\n *\n * By default, `.ownersDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.ownersDefinedIn(\"owners\", \"oidc\")` to use OIDC based authentication to designate the owner.\n *\n * To change the specific claim that should be used as the user identifier within the owners field, chain the\n * `.identityClaim(...)` method.\n *\n * @param ownersField the field that contains the owners information\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n ownersDefinedIn(ownersField, provider) {\n validateProvider(provider, OwnerProviders);\n return authData({\n strategy: 'owner',\n provider,\n groupOrOwnerField: ownersField,\n multiOwner: true,\n }, {\n to,\n identityClaim,\n });\n },\n /**\n * Authorize a specific user group. Provide the name of the specific user group to have access.\n *\n * By default, `.group()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.group(\"group-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier, chain the\n * `.withClaimIn(...)` method.\n * @param group the name of the group to authorize\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n group(group, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups: [group],\n }, {\n to,\n withClaimIn,\n });\n },\n /**\n * Authorize multiple specific user groups. Provide the names of the specific user groups to have access.\n *\n * By default, `.groups()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groups([\"group-a\", \"group-b\"], \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier, chain the\n * `.withClaimIn(...)` method.\n * @param groups the names of the group to authorize defined as an array\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groups(groups, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups,\n }, {\n to,\n withClaimIn,\n });\n },\n /**\n * Authorize if a user is part of a group defined in a data model field.\n *\n * By default, `.groupDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groupDefinedIn(\"field-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier within the groups field, chain the\n * `.withClaimIn(...)` method.\n * @param groupsField the field that should store the authorized user group information\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groupDefinedIn(groupsField, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groupOrOwnerField: groupsField,\n }, {\n to,\n withClaimIn,\n });\n },\n /**\n * Authorize if a user is part of a one of the groups defined in a data model field.\n *\n * By default, `.groupsDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groupsDefinedIn(\"field-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier within the groups field, chain the\n * `.withClaimIn(...)` method.\n * @param groupsField the field that should store the list of authorized user groups\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groupsDefinedIn(groupsField, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groupOrOwnerField: groupsField,\n multiOwner: true,\n }, {\n to,\n withClaimIn,\n });\n },\n custom(provider) {\n return authData({\n strategy: 'custom',\n provider,\n }, {\n to,\n });\n },\n resource(fn) {\n return resourceAuthData(fn, {\n to: resourceTo,\n });\n },\n};\n/**\n * This is a copy of the {@link allow} defined above, with modifications for custom operations.\n *\n * Removed builder methods:\n *\n * * `owner`\n * * `ownerDefinedIn`\n * * `ownersDefinedIn`\n * * `groupDefinedIn`\n * * `groupsDefinedIn`\n * * `resource`\n * * `.to()` builder method from each available rule builder\n */\nexport const allowForCustomOperations = {\n /**\n * Authorize unauthenticated users by using API key based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n publicApiKey() {\n return authData({\n strategy: 'public',\n provider: 'apiKey',\n }, {});\n },\n /**\n * Authorize unauthenticated users by using identityPool based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n guest() {\n return authData({\n strategy: 'public',\n provider: 'identityPool',\n }, {});\n },\n /**\n * Authorize authenticated users. By default, `.private()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.authenticated(\"identityPool\")` or `.authenticated(\"oidc\")` to use Identity Pool or OIDC based authorization for authenticated users.\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n authenticated(provider) {\n validateProvider(provider, PrivateProviders);\n return authData({\n strategy: 'private',\n provider,\n }, {});\n },\n /**\n * Authorize a specific user group. Provide the name of the specific user group to have access.\n *\n * By default, `.group()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.group(\"group-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * @param group the name of the group to authorize\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n group(group, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups: [group],\n }, {});\n },\n /**\n * Authorize multiple specific user groups. Provide the names of the specific user groups to have access.\n *\n * By default, `.groups()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groups([\"group-a\", \"group-b\"], \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * @param groups the names of the group to authorize defined as an array\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groups(groups, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups,\n }, {});\n },\n custom(provider) {\n return authData({\n strategy: 'custom',\n provider,\n }, {});\n },\n};\nexport const allowForConversations = {\n owner() {\n return authData({\n strategy: 'owner',\n provider: 'userPools',\n }, {\n to,\n identityClaim,\n });\n },\n};\nfunction resourceTo(operations) {\n this[__data].operations = operations;\n return omit(this, 'to');\n}\nfunction resourceAuthData(resource, builderMethods) {\n return {\n [__data]: {\n strategy: 'resource',\n resource,\n },\n ...builderMethods,\n };\n}\nexport const accessData = (authorization) => authorization[__data];\n// TODO: delete when we make resource auth available at each level in the schema (model, field)\nexport const accessSchemaData = (authorization) => authorization[__data];\n"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG;AACzB,IAAI,QAAQ;AACZ,IAAI,cAAc;AAClB,IAAI,WAAW;AACf,IAAI,MAAM;AACV,IAAI,UAAU;AACd,EAAE;AACF;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE;AAC1D;AACA;AACA;AACY,MAAC,gBAAgB,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE;AACtE;AACA;AACA;AACY,MAAC,cAAc,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE;AACpD;AACA;AACA;AACY,MAAC,cAAc,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE;AACpD;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,UAAU,EAAE;AAChC,MAAC,UAAU,GAAG;AAC1B,IAAI,QAAQ;AACZ,IAAI,S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AAG,cAAc;AACzB,KAAK,CAAC;AACN,CAAC;AACW,MAAC,UAAU,GAAG,CAAC,aAAa,KAAK,aAAa,CAAC,MAAM,EAAE;AACnE;AACY,MAAC,gBAAgB,GAAG,CAAC,aAAa,KAAK,aAAa,CAAC,MAAM;;;;"}
|
|
1
|
+
{"version":3,"file":"Authorization.mjs","sources":["../../src/Authorization.ts"],"sourcesContent":["const __data = Symbol('data');\n/**\n * All possible providers.\n *\n * This list should not be used if you need to restrict available providers\n * according to an auth strategcy. E.g., `public` auth can only be facilitated\n * by `apiKey` and `identityPool` providers.\n */\nexport const Providers = [\n 'apiKey',\n 'identityPool',\n 'userPools',\n 'oidc',\n 'function',\n];\n/**\n * The subset of auth providers that can facilitate `public` auth.\n */\nexport const PublicProviders = ['apiKey', 'identityPool'];\n/**\n * The subset of auth providers that can facilitate `private` auth.\n */\nexport const PrivateProviders = ['userPools', 'oidc', 'identityPool'];\n/**\n * The subset of auth providers that can facilitate `owner` auth.\n */\nexport const OwnerProviders = ['userPools', 'oidc'];\n/**\n * The subset of auth providers that can facilitate `group` auth.\n */\nexport const GroupProviders = ['userPools', 'oidc'];\n/**\n * The subset of auth providers that can facilitate `custom` auth.\n */\nexport const CustomProviders = ['function'];\nexport const Strategies = [\n 'public',\n 'private',\n 'owner',\n 'groups',\n 'custom',\n];\n/**\n * The operations that can be performed against an API.\n */\nexport const Operations = [\n 'create',\n 'update',\n 'delete',\n 'read',\n 'get',\n 'list',\n 'sync',\n 'listen',\n 'search',\n];\n/**\n * The operations that can be performed against an API by a Lambda function.\n */\nexport const ResourceOperations = ['query', 'mutate', 'listen'];\n/**\n * Creates a shallow copy of an object with an individual field pruned away.\n *\n * @param original The original object to prune.\n * @param without The field to prune.\n * @returns The pruned object.\n */\nfunction omit(original, without) {\n const pruned = { ...original };\n delete pruned[without];\n return pruned;\n}\nfunction to(operations) {\n this[__data].operations = operations;\n return omit(this, 'to');\n}\n/**\n * Specifies a property of the identity JWT to use in place of `sub::username`\n * as the value to match against the owner field for authorization.\n *\n * @param this Authorization object to operate against.\n * @param property A property of identity JWT.\n * @returns A copy of the Authorization object with the claim attached.\n */\nfunction identityClaim(property) {\n this[__data].identityClaim = property;\n return omit(this, 'identityClaim');\n}\nfunction withClaimIn(property) {\n this[__data].groupClaim = property;\n return omit(this, 'withClaimIn');\n}\nfunction validateProvider(needle, haystack) {\n if (needle && !haystack.includes(needle)) {\n throw new Error(`Invalid provider (${needle}) given!`);\n }\n}\nfunction authData(defaults, builderMethods) {\n return {\n [__data]: {\n strategy: 'public',\n provider: undefined,\n operations: undefined,\n groupOrOwnerField: undefined,\n multiOwner: false,\n identityClaim: undefined,\n groups: undefined,\n ...defaults,\n },\n ...builderMethods,\n };\n}\n/**\n * Defines an authorization rule for your data models and fields. First choose an authorization strategy (`public`,\n * `private`, `owner`, `group`, or `custom`), then choose an auth provider (`apiKey`, `identitypool`, `userPools`, `oidc`, or `function`)\n * and optionally use `.to(...)` to specify the operations that can be performed against your data models and fields.\n */\nexport const allow = {\n /**\n * Authorize unauthenticated users by using API key based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n publicApiKey() {\n return authData({\n strategy: 'public',\n provider: 'apiKey',\n }, {\n to,\n });\n },\n /**\n * Authorize unauthenticated users by using IDENTITYPOOL based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n guest() {\n return authData({\n strategy: 'public',\n provider: 'identityPool',\n }, {\n to,\n });\n },\n /**\n * Authorize authenticated users. By default, `.authenticated()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.authenticated(\"identityPool\")` or `.authenticated(\"oidc\")` to use identityPool or OIDC based authorization for authenticated users.\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n authenticated(provider) {\n validateProvider(provider, PrivateProviders);\n return authData({\n strategy: 'private',\n provider,\n }, {\n to,\n });\n },\n /**\n * Authorize access on a per-user (owner) basis. By setting owner-based authorization, a new `owner: a.string()`\n * field will be added to the model to store which user \"owns\" the item. Upon item creation, the \"owner field\" is\n * auto-populated with the authenticated user's information. If you want to specify which field should be used as\n * the owner field, you can use the `ownerDefinedIn` builder function instead.\n *\n * By default, `.owner()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.owner(\"oidc\")` to use OIDC based authentication to designate the owner.\n *\n * To change the specific claim that should be used as the user identifier within the owner field, chain the\n * `.identityClaim(...)` method.\n *\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n owner(provider) {\n validateProvider(provider, OwnerProviders);\n return authData({\n strategy: 'owner',\n provider,\n groupOrOwnerField: 'owner',\n }, {\n to,\n identityClaim,\n });\n },\n /**\n * Authorize access on a per-user (owner) basis with specifying which field should be used as the owner field.\n *\n * By default, `.owner()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.ownerDefinedIn(\"owner\", \"oidc\")` to use OIDC based authentication to designate the owner.\n *\n * To change the specific claim that should be used as the user identifier within the owner field, chain the\n * `.identityClaim(...)` method.\n *\n * @param ownerField the field that contains the owner information\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n ownerDefinedIn(ownerField, provider) {\n validateProvider(provider, OwnerProviders);\n return authData({\n strategy: 'owner',\n provider,\n groupOrOwnerField: ownerField,\n }, {\n to,\n identityClaim,\n });\n },\n /**\n * Authorize access for multi-user / multi-owner access. By setting multi-owner-based authorization, a new `owners: a.string().array()`\n * field will be added to the model to store which users \"own\" the item. Upon item creation, the \"owners field\" is\n * auto-populated with the authenticated user's information. To grant other users access to the item, append their user identifier into the `owners` array.\n *\n * You can specify which field should be used as the owners field by passing the `ownersField` parameter.\n *\n * By default, `.ownersDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.ownersDefinedIn(\"owners\", \"oidc\")` to use OIDC based authentication to designate the owner.\n *\n * To change the specific claim that should be used as the user identifier within the owners field, chain the\n * `.identityClaim(...)` method.\n *\n * @param ownersField the field that contains the owners information\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n ownersDefinedIn(ownersField, provider) {\n validateProvider(provider, OwnerProviders);\n return authData({\n strategy: 'owner',\n provider,\n groupOrOwnerField: ownersField,\n multiOwner: true,\n }, {\n to,\n identityClaim,\n });\n },\n /**\n * Authorize a specific user group. Provide the name of the specific user group to have access.\n *\n * By default, `.group()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.group(\"group-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier, chain the\n * `.withClaimIn(...)` method.\n * @param group the name of the group to authorize\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n group(group, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups: [group],\n }, {\n to,\n withClaimIn,\n });\n },\n /**\n * Authorize multiple specific user groups. Provide the names of the specific user groups to have access.\n *\n * By default, `.groups()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groups([\"group-a\", \"group-b\"], \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier, chain the\n * `.withClaimIn(...)` method.\n * @param groups the names of the group to authorize defined as an array\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groups(groups, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups,\n }, {\n to,\n withClaimIn,\n });\n },\n /**\n * Authorize if a user is part of a group defined in a data model field.\n *\n * By default, `.groupDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groupDefinedIn(\"field-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier within the groups field, chain the\n * `.withClaimIn(...)` method.\n * @param groupsField the field that should store the authorized user group information\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groupDefinedIn(groupsField, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groupOrOwnerField: groupsField,\n }, {\n to,\n withClaimIn,\n });\n },\n /**\n * Authorize if a user is part of a one of the groups defined in a data model field.\n *\n * By default, `.groupsDefinedIn()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groupsDefinedIn(\"field-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * To change the specific claim that should be used as the user group identifier within the groups field, chain the\n * `.withClaimIn(...)` method.\n * @param groupsField the field that should store the list of authorized user groups\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groupsDefinedIn(groupsField, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groupOrOwnerField: groupsField,\n multiOwner: true,\n }, {\n to,\n withClaimIn,\n });\n },\n custom(provider) {\n return authData({\n strategy: 'custom',\n provider,\n }, {\n to,\n });\n },\n resource(fn) {\n return resourceAuthData(fn, {\n to: resourceTo,\n });\n },\n};\n/**\n * This is a copy of the {@link allow} defined above, with modifications for custom operations.\n *\n * Removed builder methods:\n *\n * * `owner`\n * * `ownerDefinedIn`\n * * `ownersDefinedIn`\n * * `groupDefinedIn`\n * * `groupsDefinedIn`\n * * `resource`\n * * `.to()` builder method from each available rule builder\n */\nexport const allowForCustomOperations = {\n /**\n * Authorize unauthenticated users by using API key based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n publicApiKey() {\n return authData({\n strategy: 'public',\n provider: 'apiKey',\n }, {});\n },\n /**\n * Authorize unauthenticated users by using identityPool based authorization.\n * @returns an authorization rule for unauthenticated users\n */\n guest() {\n return authData({\n strategy: 'public',\n provider: 'identityPool',\n }, {});\n },\n /**\n * Authorize authenticated users. By default, `.private()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.authenticated(\"identityPool\")` or `.authenticated(\"oidc\")` to use Identity Pool or OIDC based authorization for authenticated users.\n * @param provider the authentication provider - supports \"userPools\", \"identityPool\", or \"oidc\"\n * @returns an authorization rule for authenticated users\n */\n authenticated(provider) {\n validateProvider(provider, PrivateProviders);\n return authData({\n strategy: 'private',\n provider,\n }, {});\n },\n /**\n * Authorize a specific user group. Provide the name of the specific user group to have access.\n *\n * By default, `.group()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.group(\"group-name\", \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * @param group the name of the group to authorize\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n group(group, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups: [group],\n }, {});\n },\n /**\n * Authorize multiple specific user groups. Provide the names of the specific user groups to have access.\n *\n * By default, `.groups()` uses an Amazon Cognito user pool based authorization. You can additionally\n * use `.groups([\"group-a\", \"group-b\"], \"oidc\")` to use OIDC based authentication to designate the user group.\n *\n * @param groups the names of the group to authorize defined as an array\n * @param provider the authentication provider - supports \"userPools\" or \"oidc\"\n * @returns an authorization rule to grant access by a specific group\n */\n groups(groups, provider) {\n return authData({\n strategy: 'groups',\n provider,\n groups,\n }, {});\n },\n custom(provider) {\n return authData({\n strategy: 'custom',\n provider,\n }, {});\n },\n};\nexport const allowForConversations = {\n owner() {\n return authData({\n strategy: 'owner',\n provider: 'userPools',\n }, {\n to,\n identityClaim,\n });\n },\n};\nfunction resourceTo(operations) {\n this[__data].operations = operations;\n return omit(this, 'to');\n}\nfunction resourceAuthData(resource, builderMethods) {\n return {\n [__data]: {\n strategy: 'resource',\n resource,\n },\n ...builderMethods,\n };\n}\nexport const accessData = (authorization) => authorization[__data];\n// TODO: delete when we make resource auth available at each level in the schema (model, field)\nexport const accessSchemaData = (authorization) => authorization[__data];\n"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG;AACzB,IAAI,QAAQ;AACZ,IAAI,cAAc;AAClB,IAAI,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OAAO;AACX,QAAQ,CAAC,MAAM,GAAG;AAClB,YAAY,QAAQ,EAAE,UAAU;AAChC,YAAY,QAAQ;AACpB,SAAS;AACT,QAAQ,GAAG,cAAc;AACzB,KAAK;AACL;AACY,MAAC,UAAU,GAAG,CAAC,aAAa,KAAK,aAAa,CAAC,MAAM;AACjE;AACY,MAAC,gBAAgB,GAAG,CAAC,aAAa,KAAK,aAAa,CAAC,MAAM;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CombineSchema.mjs","sources":["../../src/CombineSchema.ts"],"sourcesContent":["import { brand } from './util';\nconst COMBINED_SCHEMA_LIMIT = 50;\nconst CombinedSchemaBrandName = 'CombinedSchema';\nexport const combinedSchemaBrand = brand(CombinedSchemaBrandName);\n/**\n * The interface for merging up to 50 schemas into a single API.\n * @param schemas The schemas to combine into a single API\n * @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)\n * or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)\n */\nexport function combine(schemas) {\n return internalCombine(schemas);\n}\nfunction internalCombine(schemas) {\n validateDuplicateTypeNames(schemas);\n const combined = {\n ...combinedSchemaBrand,\n schemas: schemas,\n };\n for (const schema of combined.schemas) {\n schema.context = combined;\n }\n return combined;\n}\nfunction validateDuplicateTypeNames(schemas) {\n const allSchemaKeys = schemas.flatMap((s) => Object.keys(s.data.types));\n const keySet = new Set();\n const duplicateKeySet = new Set();\n allSchemaKeys.forEach((key) => {\n if (keySet.has(key)) {\n duplicateKeySet.add(key);\n }\n else {\n keySet.add(key);\n }\n });\n if (duplicateKeySet.size > 0) {\n throw new Error(`The schemas you are attempting to combine have a name collision. Please remove or rename ${Array.from(duplicateKeySet).join(', ')}.`);\n }\n}\n"],"names":[],"mappings":";;AAEA,MAAM,uBAAuB,GAAG,gBAAgB
|
|
1
|
+
{"version":3,"file":"CombineSchema.mjs","sources":["../../src/CombineSchema.ts"],"sourcesContent":["import { brand } from './util';\nconst COMBINED_SCHEMA_LIMIT = 50;\nconst CombinedSchemaBrandName = 'CombinedSchema';\nexport const combinedSchemaBrand = brand(CombinedSchemaBrandName);\n/**\n * The interface for merging up to 50 schemas into a single API.\n * @param schemas The schemas to combine into a single API\n * @returns An API and data model definition to be deployed with Amplify (Gen 2) experience (`processSchema(...)`)\n * or with the Amplify Data CDK construct (`@aws-amplify/data-construct`)\n */\nexport function combine(schemas) {\n return internalCombine(schemas);\n}\nfunction internalCombine(schemas) {\n validateDuplicateTypeNames(schemas);\n const combined = {\n ...combinedSchemaBrand,\n schemas: schemas,\n };\n for (const schema of combined.schemas) {\n schema.context = combined;\n }\n return combined;\n}\nfunction validateDuplicateTypeNames(schemas) {\n const allSchemaKeys = schemas.flatMap((s) => Object.keys(s.data.types));\n const keySet = new Set();\n const duplicateKeySet = new Set();\n allSchemaKeys.forEach((key) => {\n if (keySet.has(key)) {\n duplicateKeySet.add(key);\n }\n else {\n keySet.add(key);\n }\n });\n if (duplicateKeySet.size > 0) {\n throw new Error(`The schemas you are attempting to combine have a name collision. Please remove or rename ${Array.from(duplicateKeySet).join(', ')}.`);\n }\n}\n"],"names":[],"mappings":";;AAEA,MAAM,uBAAuB,GAAG,gBAAgB;AACpC,MAAC,mBAAmB,GAAG,KAAK,CAAC,uBAAuB;AAChE;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,OAAO,CAAC,OAAO,EAAE;AACjC,IAAI,OAAO,eAAe,CAAC,OAAO,CAAC;AACnC;AACA,SAAS,eAAe,CAAC,OAAO,EAAE;AAClC,IAAI,0BAA0B,CAAC,OAAO,CAAC;AACvC,IAAI,MAAM,QAAQ,GAAG;AACrB,QAAQ,GAAG,mBAAmB;AAC9B,QAAQ,OAAO,EAAE,OAAO;AACxB,KAAK;AACL,IAAI,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE;AAC3C,QAAQ,MAAM,CAAC,OAAO,GAAG,QAAQ;AACjC;AACA,IAAI,OAAO,QAAQ;AACnB;AACA,SAAS,0BAA0B,CAAC,OAAO,EAAE;AAC7C,IAAI,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3E,IAAI,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE;AAC5B,IAAI,MAAM,eAAe,GAAG,IAAI,GAAG,EAAE;AACrC,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK;AACnC,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;AAC7B,YAAY,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;AACpC;AACA,aAAa;AACb,YAAY,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;AAC3B;AACA,KAAK,CAAC;AACN,IAAI,IAAI,eAAe,CAAC,IAAI,GAAG,CAAC,EAAE;AAClC,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,yFAAyF,EAAE,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9J;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomOperation.mjs","sources":["../../src/CustomOperation.ts"],"sourcesContent":["import { brand } from './util';\nimport { allowForCustomOperations, } from './Authorization';\nimport { brandSymbol } from './util/Brand';\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nconst generationBrand = 'generationCustomOperation';\nexport const CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n 'Generation',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...brand(brandValue) };\n}\nfunction _custom(typeName, brand, input) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n input,\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 if (lastHandlerIsAsyncFunction(handlers)) {\n data.returnType = eventInvocationResponse;\n }\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}\nconst eventInvocationResponse = {\n data: {\n type: 'ref',\n link: 'EventInvocationResponse',\n valueRequired: false,\n array: false,\n arrayRequired: false,\n mutationOperations: [],\n authorization: [],\n },\n};\nfunction lastHandlerIsAsyncFunction(handlers) {\n const lastHandlerBrandSymbol = Array.isArray(handlers)\n ? handlers[handlers.length - 1][brandSymbol]\n : handlers[brandSymbol];\n return lastHandlerBrandSymbol === 'asyncFunctionHandler';\n}\n/**\n * Define an AI generation route for single request-response interaction with specified AI model.\n * @example\n * makeRecipe: a.generation({\n * aiModel: { resourcePath },\n * systemPrompt: 'Please make a recipe from the provided ingredients',\n * })\n * .arguments({ ingredients: a.string().array() })\n * .returns(a.ref(\"Recipe\"))\n * @returns a generation route definition\n */\nexport function generation(input) {\n return _custom('Generation', generationBrand, input);\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,UAAU,GAAG,sBAAsB
|
|
1
|
+
{"version":3,"file":"CustomOperation.mjs","sources":["../../src/CustomOperation.ts"],"sourcesContent":["import { brand } from './util';\nimport { allowForCustomOperations, } from './Authorization';\nimport { brandSymbol } from './util/Brand';\nconst queryBrand = 'queryCustomOperation';\nconst mutationBrand = 'mutationCustomOperation';\nconst subscriptionBrand = 'subscriptionCustomOperation';\nconst generationBrand = 'generationCustomOperation';\nexport const CustomOperationNames = [\n 'Query',\n 'Mutation',\n 'Subscription',\n 'Generation',\n];\nfunction brandedBuilder(builder, brandValue) {\n return { ...builder, ...brand(brandValue) };\n}\nfunction _custom(typeName, brand, input) {\n const data = {\n arguments: {},\n returnType: null,\n authorization: [],\n typeName: typeName,\n handlers: null,\n subscriptionSource: [],\n input,\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 if (lastHandlerIsAsyncFunction(handlers)) {\n data.returnType = eventInvocationResponse;\n }\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}\nconst eventInvocationResponse = {\n data: {\n type: 'ref',\n link: 'EventInvocationResponse',\n valueRequired: false,\n array: false,\n arrayRequired: false,\n mutationOperations: [],\n authorization: [],\n },\n};\nfunction lastHandlerIsAsyncFunction(handlers) {\n const lastHandlerBrandSymbol = Array.isArray(handlers)\n ? handlers[handlers.length - 1][brandSymbol]\n : handlers[brandSymbol];\n return lastHandlerBrandSymbol === 'asyncFunctionHandler';\n}\n/**\n * Define an AI generation route for single request-response interaction with specified AI model.\n * @example\n * makeRecipe: a.generation({\n * aiModel: { resourcePath },\n * systemPrompt: 'Please make a recipe from the provided ingredients',\n * })\n * .arguments({ ingredients: a.string().array() })\n * .returns(a.ref(\"Recipe\"))\n * @returns a generation route definition\n */\nexport function generation(input) {\n return _custom('Generation', generationBrand, input);\n}\n"],"names":[],"mappings":";;;AAGA,MAAM,UAAU,GAAG,sBAAsB;AACzC,MAAM,aAAa,GAAG,yBAAyB;AAC/C,MAAM,iBAAiB,GAAG,6BAA6B;AACvD,MAAM,eAAe,GAAG,2BAA2B;AACvC,MAAC,oBAAoB,GAAG;AACpC,IAAI,OAAO;AACX,IAAI,UAAU;AACd,IAAI,cAAc;AAClB,IAAI,YAAY;AAChB;AACA,SAAS,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE;AAC7C,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,EAAE;AAC/C;AACA,SAAS,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;AACzC,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,IAAI;AACxB,QAAQ,aAAa,EAAE,EAAE;AACzB,QAAQ,QAAQ,EAAE,QAAQ;AAC1B,QAAQ,QAAQ,EAAE,IAAI;AACtB,QAAQ,kBAAkB,EAAE,EAAE;AAC9B,QAAQ,KAAK;AACb,KAAK;AACL,IAAI,MAAM,OAAO,GAAG,cAAc,CAAC;AACnC,QAAQ,SAAS,CAAC,IAAI,EAAE;AACxB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI;AACjC,YAAY,OAAO,IAAI;AACvB,SAAS;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Aa,CAAC;AAC7C;AACA;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;AACrD;AACA,MAAM,uBAAuB,GAAG;AAChC,IAAI,IAAI,EAAE;AACV,QAAQ,IAAI,EAAE,KAAK;AACnB,QAAQ,IAAI,EAAE,yBAAyB;AACvC,QAAQ,aAAa,EAAE,KAAK;AAC5B,QAAQ,KAAK,EAAE,KAAK;AACpB,QAAQ,aAAa,EAAE,KAAK;AAC5B,QAAQ,kBAAkB,EAAE,EAAE;AAC9B,QAAQ,aAAa,EAAE,EAAE;AACzB,KAAK;AACL,CAAC;AACD,SAAS,0BAA0B,CAAC,QAAQ,EAAE;AAC9C,IAAI,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ;AACzD,UAAU,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,WAAW;AACnD,UAAU,QAAQ,CAAC,WAAW,CAAC;AAC/B,IAAI,OAAO,sBAAsB,KAAK,sBAAsB;AAC5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,UAAU,CAAC,KAAK,EAAE;AAClC,IAAI,OAAO,OAAO,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,CAAC;AACxD;;;;"}
|
|
@@ -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}\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
|
|
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;AACL,IAAI,OAAO,EAAE,IAAI,EAAE;AACnB;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;AACO,SAAS,UAAU,CAAC,MAAM,EAAE;AACnC,IAAI,OAAO,WAAW,CAAC,MAAM,CAAC;AAC9B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumType.mjs","sources":["../../src/EnumType.ts"],"sourcesContent":["function _enum(values) {\n const data = {\n type: 'enum',\n values,\n };\n return data;\n}\n/**\n * this type param pattern allows us to infer literal type values from the array without using the `as const` suffix\n */\nexport function enumType(values) {\n return _enum(values);\n}\n"],"names":[],"mappings":"AAAA,SAAS,KAAK,CAAC,MAAM,EAAE;AACvB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,EAAE,MAAM;AACpB,QAAQ,MAAM;AACd,KAAK
|
|
1
|
+
{"version":3,"file":"EnumType.mjs","sources":["../../src/EnumType.ts"],"sourcesContent":["function _enum(values) {\n const data = {\n type: 'enum',\n values,\n };\n return data;\n}\n/**\n * this type param pattern allows us to infer literal type values from the array without using the `as const` suffix\n */\nexport function enumType(values) {\n return _enum(values);\n}\n"],"names":[],"mappings":"AAAA,SAAS,KAAK,CAAC,MAAM,EAAE;AACvB,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,IAAI,EAAE,MAAM;AACpB,QAAQ,MAAM;AACd,KAAK;AACL,IAAI,OAAO,IAAI;AACf;AACA;AACA;AACA;AACO,SAAS,QAAQ,CAAC,MAAM,EAAE;AACjC,IAAI,OAAO,KAAK,CAAC,MAAM,CAAC;AACxB;;;;"}
|
package/dist/esm/Handler.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Handler.mjs","sources":["../../src/Handler.ts"],"sourcesContent":["import { brand } from './util';\nconst dataSymbol = Symbol('Data');\nfunction buildHandler(brandName) {\n return brand(brandName);\n}\nexport function getHandlerData(handler) {\n return handler[dataSymbol];\n}\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';\nconst asyncFunctionHandlerBrand = 'asyncFunctionHandler';\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 {\n [dataSymbol]: {\n handler: fn,\n invocationType: 'RequestResponse',\n },\n async() {\n return _async(this);\n },\n ...buildHandler(functionHandlerBrand),\n };\n}\nfunction _async(fnHandler) {\n return {\n [dataSymbol]: {\n handler: fnHandler[dataSymbol].handler,\n invocationType: 'Event',\n },\n ...buildHandler(asyncFunctionHandlerBrand),\n };\n}\n//#endregion\nexport const handler = {\n inlineSql,\n sqlReference,\n custom,\n function: fcn,\n};\n"],"names":[],"mappings":";;AACA,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC
|
|
1
|
+
{"version":3,"file":"Handler.mjs","sources":["../../src/Handler.ts"],"sourcesContent":["import { brand } from './util';\nconst dataSymbol = Symbol('Data');\nfunction buildHandler(brandName) {\n return brand(brandName);\n}\nexport function getHandlerData(handler) {\n return handler[dataSymbol];\n}\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';\nconst asyncFunctionHandlerBrand = 'asyncFunctionHandler';\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 {\n [dataSymbol]: {\n handler: fn,\n invocationType: 'RequestResponse',\n },\n async() {\n return _async(this);\n },\n ...buildHandler(functionHandlerBrand),\n };\n}\nfunction _async(fnHandler) {\n return {\n [dataSymbol]: {\n handler: fnHandler[dataSymbol].handler,\n invocationType: 'Event',\n },\n ...buildHandler(asyncFunctionHandlerBrand),\n };\n}\n//#endregion\nexport const handler = {\n inlineSql,\n sqlReference,\n custom,\n function: fcn,\n};\n"],"names":[],"mappings":";;AACA,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;AACjC,SAAS,YAAY,CAAC,SAAS,EAAE;AACjC,IAAI,OAAO,KAAK,CAAC,SAAS,CAAC;AAC3B;AACO,SAAS,cAAc,CAAC,OAAO,EAAE;AACxC,IAAI,OAAO,OAAO,CAAC,UAAU,CAAC;AAC9B;AACA;AACA,MAAM,cAAc,GAAG,WAAW;AAClC,SAAS,SAAS,CAAC,GAAG,EAAE;AACxB,IAAI,OAAO,EAAE,CAAC,UAAU,GAAG,GAAG,EAAE,GAAG,YAAY,CAAC,cAAc,CAAC,EAAE;AACjE;AACA;AACA;AACA,MAAM,iBAAiB,GAAG,cAAc;AACxC,SAAS,YAAY,CAAC,WAAW,EAAE;AACnC;AACA,IAAI,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK;AACnC,IAAI,OAAO;AACX,QAAQ,CAAC,UAAU,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE;AACnD,QAAQ,GAAG,YAAY,CAAC,iBAAiB,CAAC;AAC1C,KAAK;AACL;AACA,MAAM,kBAAkB,GAAG,eAAe;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AllowModifier, Authorization } from './Authorization';
|
|
2
2
|
import type { methodKeyOf, satisfy } from './util/usedMethods.js';
|
|
3
3
|
import type { brandSymbol } from './util/Brand.js';
|
|
4
|
+
import { ValidationRule, FieldTypeToValidationBuilder } from './Validate';
|
|
4
5
|
/**
|
|
5
6
|
* Used to "attach" auth types to ModelField without exposing them on the builder.
|
|
6
7
|
*/
|
|
@@ -41,6 +42,7 @@ type FieldData = {
|
|
|
41
42
|
arrayRequired: boolean;
|
|
42
43
|
default: undefined | symbol | ModelFieldTypeParamOuter;
|
|
43
44
|
authorization: Authorization<any, any, any>[];
|
|
45
|
+
validation: ValidationRule[];
|
|
44
46
|
};
|
|
45
47
|
type ModelFieldTypeParamInner = string | number | boolean | Date | Json | null;
|
|
46
48
|
/**
|
|
@@ -56,16 +58,18 @@ export type ModelFieldTypeParamOuter = ModelFieldTypeParamInner | Array<ModelFie
|
|
|
56
58
|
export type Nullable<T> = T | null;
|
|
57
59
|
export type Required<T> = Exclude<T, null>;
|
|
58
60
|
export type ArrayField<T> = [T] extends [ModelFieldTypeParamInner] ? Array<T> | null : never;
|
|
59
|
-
export type BaseModelField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamOuter> = ModelField<T, UsableModelFieldKey, any>;
|
|
60
|
-
export type UsableModelFieldKey = satisfy<methodKeyOf<ModelField>, 'required' | 'default' | 'authorization' | 'array'>;
|
|
61
|
+
export type BaseModelField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamOuter, FT extends ModelFieldType = ModelFieldType> = ModelField<T, UsableModelFieldKey, any, FT>;
|
|
62
|
+
export type UsableModelFieldKey = satisfy<methodKeyOf<ModelField>, 'required' | 'default' | 'authorization' | 'array' | 'validate'>;
|
|
61
63
|
/**
|
|
62
64
|
* Public API for the chainable builder methods exposed by Model Field.
|
|
63
65
|
* The type is narrowing e.g., after calling .array() it will be omitted from intellisense suggestions
|
|
64
66
|
*
|
|
65
67
|
* @typeParam T - holds the JS data type of the field
|
|
66
68
|
* @typeParam UsedMethod - union of strings representing already-invoked method names. Used to improve Intellisense
|
|
69
|
+
* @typeParam Auth - type of the authorization rules attached to the field
|
|
70
|
+
* @typeParam FT - specific ModelFieldType of the field
|
|
67
71
|
*/
|
|
68
|
-
export type ModelField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamOuter, UsedMethod extends UsableModelFieldKey = never, Auth = undefined> = Omit<{
|
|
72
|
+
export type ModelField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamOuter, UsedMethod extends UsableModelFieldKey = never, Auth = undefined, FT extends ModelFieldType = ModelFieldType> = Omit<{
|
|
69
73
|
[__auth]?: Auth;
|
|
70
74
|
[brandSymbol]: typeof brandName;
|
|
71
75
|
/**
|
|
@@ -74,108 +78,119 @@ export type ModelField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamO
|
|
|
74
78
|
* some property on the type is guaranteed to reference `T`
|
|
75
79
|
* Context: https://github.com/aws-amplify/amplify-data/pull/406/files#r1869481467
|
|
76
80
|
*/
|
|
77
|
-
[internal](): ModelField<T>;
|
|
81
|
+
[internal](): ModelField<T, UsedMethod, Auth, FT>;
|
|
78
82
|
/**
|
|
79
83
|
* Marks a field as required.
|
|
80
84
|
*/
|
|
81
|
-
required(): ModelField<Required<T>, UsedMethod | 'required'>;
|
|
85
|
+
required(): ModelField<Required<T>, UsedMethod | 'required', Auth, FT>;
|
|
82
86
|
/**
|
|
83
87
|
* Converts a field type definition to an array of the field type.
|
|
84
88
|
*/
|
|
85
|
-
array(): ModelField<ArrayField<T>, Exclude<UsedMethod, 'required'> | 'array'>;
|
|
89
|
+
array(): ModelField<ArrayField<T>, Exclude<UsedMethod, 'required'> | 'array' | 'validate', Auth, FT>;
|
|
86
90
|
/**
|
|
87
91
|
* Sets a default value for the scalar type.
|
|
88
92
|
* @param value the default value
|
|
89
93
|
*/
|
|
90
|
-
default(value?: ModelFieldTypeParamOuter): ModelField<T, UsedMethod | 'default'>;
|
|
94
|
+
default(value?: ModelFieldTypeParamOuter): ModelField<T, UsedMethod | 'default', Auth, FT>;
|
|
91
95
|
/**
|
|
92
96
|
* Configures field-level authorization rules. Pass in an array of authorizations `(allow => allow.____)` to mix and match
|
|
93
97
|
* multiple authorization rules for this field.
|
|
94
98
|
*/
|
|
95
|
-
authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelField<T, UsedMethod | 'authorization', AuthRuleType>;
|
|
99
|
+
authorization<AuthRuleType extends Authorization<any, any, any>>(callback: (allow: Omit<AllowModifier, 'resource'>) => AuthRuleType | AuthRuleType[]): ModelField<T, UsedMethod | 'authorization', AuthRuleType, FT>;
|
|
100
|
+
/**
|
|
101
|
+
* Configures field-level validation rules.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* a.integer().validate(v => v.gt(0, 'Integer must be greater than 0'))
|
|
105
|
+
* a.float().validate(v => v.gt(0.99, 'Float must be greater than 0.99'))
|
|
106
|
+
* a.string().validate(v => v.minLength(5, 'String must be at least 5 characters'))
|
|
107
|
+
*
|
|
108
|
+
* @param callback - A function that receives a validation builder object for the field type
|
|
109
|
+
*/
|
|
110
|
+
validate(callback: (v: FieldTypeToValidationBuilder<T, FT>) => void): ModelField<T, UsedMethod | 'validate' | 'default' | 'array', Auth, FT>;
|
|
96
111
|
}, UsedMethod>;
|
|
97
112
|
/**
|
|
98
113
|
* Internal representation of Model Field that exposes the `data` property.
|
|
99
114
|
* Used at buildtime.
|
|
100
115
|
*/
|
|
101
|
-
export
|
|
116
|
+
export type InternalField<T extends ModelFieldTypeParamOuter = ModelFieldTypeParamOuter, UsedMethod extends UsableModelFieldKey = never, Auth = undefined, FT extends ModelFieldType = ModelFieldType> = ModelField<T, UsedMethod, Auth, FT> & {
|
|
102
117
|
data: FieldData;
|
|
103
|
-
}
|
|
118
|
+
};
|
|
104
119
|
/**
|
|
105
120
|
* A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.
|
|
106
121
|
* If not specified on create operations, a ULID will be auto-generated service-side.
|
|
107
122
|
* @returns ID field definition
|
|
108
123
|
*/
|
|
109
|
-
export declare function id(): ModelField<Nullable<string
|
|
124
|
+
export declare function id(): ModelField<Nullable<string>, never, undefined, ModelFieldType.Id>;
|
|
110
125
|
/**
|
|
111
126
|
* A string scalar type that is represented server-side as a UTF-8 character sequence.
|
|
112
127
|
* @returns string field definition
|
|
113
128
|
*/
|
|
114
|
-
export declare function string(): ModelField<Nullable<string
|
|
129
|
+
export declare function string(): ModelField<Nullable<string>, never, undefined, ModelFieldType.String>;
|
|
115
130
|
/**
|
|
116
131
|
* An integer scalar type with a supported value range between -(2^31) and 2^31-1.
|
|
117
132
|
* @returns integer field definition
|
|
118
133
|
*/
|
|
119
|
-
export declare function integer(): ModelField<Nullable<number
|
|
134
|
+
export declare function integer(): ModelField<Nullable<number>, never, undefined, ModelFieldType.Integer>;
|
|
120
135
|
/**
|
|
121
136
|
* A float scalar type following represented server-side as an IEEE 754 floating point value.
|
|
122
137
|
* @returns float field definition
|
|
123
138
|
*/
|
|
124
|
-
export declare function float(): ModelField<Nullable<number
|
|
139
|
+
export declare function float(): ModelField<Nullable<number>, never, undefined, ModelFieldType.Float>;
|
|
125
140
|
/**
|
|
126
141
|
* A boolean scalar type that can be either true or false.
|
|
127
142
|
* @returns boolean field definition
|
|
128
143
|
*/
|
|
129
|
-
export declare function boolean(): ModelField<Nullable<boolean
|
|
144
|
+
export declare function boolean(): ModelField<Nullable<boolean>, never, undefined, ModelFieldType.Boolean>;
|
|
130
145
|
/**
|
|
131
146
|
* A date scalar type that is represented server-side as an extended ISO 8601 date string in the format `YYYY-MM-DD`.
|
|
132
147
|
* @returns date field definition
|
|
133
148
|
*/
|
|
134
|
-
export declare function date(): ModelField<Nullable<string
|
|
149
|
+
export declare function date(): ModelField<Nullable<string>, never, undefined, ModelFieldType.Date>;
|
|
135
150
|
/**
|
|
136
151
|
* A time scalar type that is represented server-side as an extended ISO 8601 time string in the format `hh:mm:ss.sss`.
|
|
137
152
|
* @returns time field definition
|
|
138
153
|
*/
|
|
139
|
-
export declare function time(): ModelField<Nullable<string
|
|
154
|
+
export declare function time(): ModelField<Nullable<string>, never, undefined, ModelFieldType.Time>;
|
|
140
155
|
/**
|
|
141
156
|
* A date time scalar type that is represented server-side as an extended ISO 8601 date and time string in the format `YYYY-MM-DDThh:mm:ss.sssZ`.
|
|
142
157
|
* @returns datetime field definition
|
|
143
158
|
*/
|
|
144
|
-
export declare function datetime(): ModelField<Nullable<string
|
|
159
|
+
export declare function datetime(): ModelField<Nullable<string>, never, undefined, ModelFieldType.DateTime>;
|
|
145
160
|
/**
|
|
146
161
|
* A timestamp scalar type that is represented by an integer value of the number of seconds before or after `1970-01-01-T00:00Z`.
|
|
147
162
|
* @returns timestamp field definition
|
|
148
163
|
*/
|
|
149
|
-
export declare function timestamp(): ModelField<Nullable<number
|
|
164
|
+
export declare function timestamp(): ModelField<Nullable<number>, never, undefined, ModelFieldType.Timestamp>;
|
|
150
165
|
/**
|
|
151
166
|
* An email scalar type that is represented server-side in the format `local-part@domain-part` as defined by RFC 822.
|
|
152
167
|
* @returns email field definition
|
|
153
168
|
*/
|
|
154
|
-
export declare function email(): ModelField<Nullable<string
|
|
169
|
+
export declare function email(): ModelField<Nullable<string>, never, undefined, ModelFieldType.Email>;
|
|
155
170
|
/**
|
|
156
171
|
* A JSON scalar type that is automatically parsed and loaded server-side as maps, lists, or scalar values
|
|
157
172
|
* rather than as the literal input strings.
|
|
158
173
|
* @returns JSON field definition
|
|
159
174
|
*/
|
|
160
|
-
export declare function json(): ModelField<Nullable<Json
|
|
175
|
+
export declare function json(): ModelField<Nullable<Json>, never, undefined, ModelFieldType.JSON>;
|
|
161
176
|
/**
|
|
162
177
|
* A phone number scalar type thas is stored as a string server-side. Phone numbers can contain either spaces
|
|
163
178
|
* or hyphens to separate digit groups. Phone numbers without a country code are assumed to be US/North American numbers adhering
|
|
164
179
|
* to the North American Numbering Plan.
|
|
165
180
|
* @returns phone number field definition
|
|
166
181
|
*/
|
|
167
|
-
export declare function phone(): ModelField<Nullable<string
|
|
182
|
+
export declare function phone(): ModelField<Nullable<string>, never, undefined, ModelFieldType.Phone>;
|
|
168
183
|
/**
|
|
169
184
|
* A URL scalar type as defined by RFC 1738. For example, https://www.amazon.com/dp/B000NZW3KC/ or mailto:example@example.com.
|
|
170
185
|
* URLs must contain a schema (http, mailto) and can't contain two forward slashes (//) in the path part.
|
|
171
186
|
* @returns URL field definition
|
|
172
187
|
*/
|
|
173
|
-
export declare function url(): ModelField<Nullable<string
|
|
188
|
+
export declare function url(): ModelField<Nullable<string>, never, undefined, ModelFieldType.Url>;
|
|
174
189
|
/**
|
|
175
190
|
* A valid IPv4 or IPv6 address scalar type. IPv4 addresses are expected in quad-dotted notation (123.12.34.56). IPv6 addresses
|
|
176
191
|
* are expected in non-bracketed, colon-separated format (1a2b:3c4b:🔢4567). You can include an optional CIDR suffix (123.45.67.89/16)
|
|
177
192
|
* to indicate subnet mask.
|
|
178
193
|
* @returns IP address field definition
|
|
179
194
|
*/
|
|
180
|
-
export declare function ipAddress(): ModelField<Nullable<string
|
|
195
|
+
export declare function ipAddress(): ModelField<Nullable<string>, never, undefined, ModelFieldType.IPAddress>;
|
|
181
196
|
export {};
|
package/dist/esm/ModelField.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { brand } from './util/Brand.mjs';
|
|
2
2
|
import { allow } from './Authorization.mjs';
|
|
3
|
+
import { createValidationBuilder } from './Validate.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Used to "attach" auth types to ModelField without exposing them on the builder.
|
|
@@ -59,6 +60,7 @@ function _field(fieldType) {
|
|
|
59
60
|
arrayRequired: false,
|
|
60
61
|
default: undefined,
|
|
61
62
|
authorization: [],
|
|
63
|
+
validation: [],
|
|
62
64
|
};
|
|
63
65
|
const builder = {
|
|
64
66
|
required() {
|
|
@@ -88,13 +90,18 @@ function _field(fieldType) {
|
|
|
88
90
|
_meta.lastInvokedMethod = 'authorization';
|
|
89
91
|
return this;
|
|
90
92
|
},
|
|
93
|
+
validate(callback) {
|
|
94
|
+
const { builder, getRules } = createValidationBuilder();
|
|
95
|
+
callback(builder);
|
|
96
|
+
data.validation = getRules();
|
|
97
|
+
_meta.lastInvokedMethod = 'validate';
|
|
98
|
+
return this;
|
|
99
|
+
},
|
|
91
100
|
...brand(brandName),
|
|
92
101
|
[internal]() {
|
|
93
102
|
return this;
|
|
94
103
|
},
|
|
95
104
|
};
|
|
96
|
-
// this double cast gives us a Subtyping Constraint i.e., hides `data` from the public API,
|
|
97
|
-
// but makes it available internally when needed
|
|
98
105
|
return { ...builder, data };
|
|
99
106
|
}
|
|
100
107
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelField.mjs","sources":["../../src/ModelField.ts"],"sourcesContent":["import { brand } from './util';\nimport { allow } from './Authorization';\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexport const __auth = Symbol('__auth');\n/**\n * Used by `.default()` to represent a generated field (SQL).\n */\nexport const __generated = Symbol('__generated');\nconst brandName = 'modelField';\nconst internal = Symbol('internal');\nexport var ModelFieldType;\n(function (ModelFieldType) {\n ModelFieldType[\"Id\"] = \"ID\";\n ModelFieldType[\"String\"] = \"String\";\n ModelFieldType[\"Integer\"] = \"Int\";\n ModelFieldType[\"Float\"] = \"Float\";\n ModelFieldType[\"Boolean\"] = \"Boolean\";\n ModelFieldType[\"Date\"] = \"AWSDate\";\n ModelFieldType[\"Time\"] = \"AWSTime\";\n ModelFieldType[\"DateTime\"] = \"AWSDateTime\";\n ModelFieldType[\"Timestamp\"] = \"AWSTimestamp\";\n ModelFieldType[\"Email\"] = \"AWSEmail\";\n ModelFieldType[\"JSON\"] = \"AWSJSON\";\n ModelFieldType[\"Phone\"] = \"AWSPhone\";\n ModelFieldType[\"Url\"] = \"AWSURL\";\n ModelFieldType[\"IPAddress\"] = \"AWSIPAddress\";\n})(ModelFieldType || (ModelFieldType = {}));\nexport var ModelFieldDataType;\n(function (ModelFieldDataType) {\n ModelFieldDataType[\"String\"] = \"string\";\n ModelFieldDataType[\"Number\"] = \"number\";\n ModelFieldDataType[\"Boolean\"] = \"boolean\";\n ModelFieldDataType[\"Date\"] = \"Date\";\n ModelFieldDataType[\"JSON\"] = \"any\";\n})(ModelFieldDataType || (ModelFieldDataType = {}));\n/**\n * Model Field Implementation\n *\n * @typeParam T - holds the JS data type of the field; invoking the public methods changes this type accordingly\n * @example\n * string() => T = string | null\n * string().array() => T = Array<string | null> | null\n * string().array().required() => T = Array<string | null>\n * string().required().array().required() => T = Array<string>\n *\n * @param fieldType - stores the GraphQL data type of the field\n */\nfunction _field(fieldType) {\n const _meta = {\n lastInvokedMethod: null,\n };\n const data = {\n fieldType,\n required: false,\n array: false,\n arrayRequired: false,\n default: undefined,\n authorization: [],\n };\n const builder = {\n required() {\n if (_meta.lastInvokedMethod === 'array') {\n data.arrayRequired = true;\n }\n else {\n data.required = true;\n }\n _meta.lastInvokedMethod = 'required';\n return this;\n },\n array() {\n data.array = true;\n _meta.lastInvokedMethod = 'array';\n return this;\n },\n default(val) {\n data.default = typeof val === 'undefined' ? __generated : val;\n _meta.lastInvokedMethod = 'default';\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n _meta.lastInvokedMethod = 'authorization';\n return this;\n },\n ...brand(brandName),\n [internal]() {\n return this;\n },\n };\n // this double cast gives us a Subtyping Constraint i.e., hides `data` from the public API,\n // but makes it available internally when needed\n return { ...builder, data };\n}\n/**\n * A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.\n * If not specified on create operations, a ULID will be auto-generated service-side.\n * @returns ID field definition\n */\nexport function id() {\n return _field(ModelFieldType.Id);\n}\n/**\n * A string scalar type that is represented server-side as a UTF-8 character sequence.\n * @returns string field definition\n */\nexport function string() {\n return _field(ModelFieldType.String);\n}\n/**\n * An integer scalar type with a supported value range between -(2^31) and 2^31-1.\n * @returns integer field definition\n */\nexport function integer() {\n return _field(ModelFieldType.Integer);\n}\n/**\n * A float scalar type following represented server-side as an IEEE 754 floating point value.\n * @returns float field definition\n */\nexport function float() {\n return _field(ModelFieldType.Float);\n}\n/**\n * A boolean scalar type that can be either true or false.\n * @returns boolean field definition\n */\nexport function boolean() {\n return _field(ModelFieldType.Boolean);\n}\n/**\n * A date scalar type that is represented server-side as an extended ISO 8601 date string in the format `YYYY-MM-DD`.\n * @returns date field definition\n */\nexport function date() {\n return _field(ModelFieldType.Date);\n}\n/**\n * A time scalar type that is represented server-side as an extended ISO 8601 time string in the format `hh:mm:ss.sss`.\n * @returns time field definition\n */\nexport function time() {\n return _field(ModelFieldType.Time);\n}\n/**\n * A date time scalar type that is represented server-side as an extended ISO 8601 date and time string in the format `YYYY-MM-DDThh:mm:ss.sssZ`.\n * @returns datetime field definition\n */\nexport function datetime() {\n return _field(ModelFieldType.DateTime);\n}\n/**\n * A timestamp scalar type that is represented by an integer value of the number of seconds before or after `1970-01-01-T00:00Z`.\n * @returns timestamp field definition\n */\nexport function timestamp() {\n return _field(ModelFieldType.Timestamp);\n}\n/**\n * An email scalar type that is represented server-side in the format `local-part@domain-part` as defined by RFC 822.\n * @returns email field definition\n */\nexport function email() {\n return _field(ModelFieldType.Email);\n}\n/**\n * A JSON scalar type that is automatically parsed and loaded server-side as maps, lists, or scalar values\n * rather than as the literal input strings.\n * @returns JSON field definition\n */\nexport function json() {\n return _field(ModelFieldType.JSON);\n}\n/**\n * A phone number scalar type thas is stored as a string server-side. Phone numbers can contain either spaces\n * or hyphens to separate digit groups. Phone numbers without a country code are assumed to be US/North American numbers adhering\n * to the North American Numbering Plan.\n * @returns phone number field definition\n */\nexport function phone() {\n return _field(ModelFieldType.Phone);\n}\n/**\n * A URL scalar type as defined by RFC 1738. For example, https://www.amazon.com/dp/B000NZW3KC/ or mailto:example@example.com.\n * URLs must contain a schema (http, mailto) and can't contain two forward slashes (//) in the path part.\n * @returns URL field definition\n */\nexport function url() {\n return _field(ModelFieldType.Url);\n}\n/**\n * A valid IPv4 or IPv6 address scalar type. IPv4 addresses are expected in quad-dotted notation (123.12.34.56). IPv6 addresses\n * are expected in non-bracketed, colon-separated format (1a2b:3c4b:🔢4567). You can include an optional CIDR suffix (123.45.67.89/16)\n * to indicate subnet mask.\n * @returns IP address field definition\n */\nexport function ipAddress() {\n return _field(ModelFieldType.IPAddress);\n}\n"],"names":[],"mappings":";;;AAEA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE;AACvC;AACA;AACA;AACY,MAAC,WAAW,GAAG,MAAM,CAAC,aAAa,EAAE;AACjD,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC1B,IAAC,eAAe;AAC1B,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAChC,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AACxC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;AACtC,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AACtC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAC1C,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AACvC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AACvC,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC;AAC/C,IAAI,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc,CAAC;AACjD,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;AACzC,IAAI,cAAc,CAAC,MA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CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,KAAK,GAAG;AACxB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,GAAG,GAAG;AACtB,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,SAAS,GAAG;AAC5B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;AAC5C;;;;"}
|
|
1
|
+
{"version":3,"file":"ModelField.mjs","sources":["../../src/ModelField.ts"],"sourcesContent":["import { brand } from './util';\nimport { allow } from './Authorization';\nimport { createValidationBuilder, } from './Validate';\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexport const __auth = Symbol('__auth');\n/**\n * Used by `.default()` to represent a generated field (SQL).\n */\nexport const __generated = Symbol('__generated');\nconst brandName = 'modelField';\nconst internal = Symbol('internal');\nexport var ModelFieldType;\n(function (ModelFieldType) {\n ModelFieldType[\"Id\"] = \"ID\";\n ModelFieldType[\"String\"] = \"String\";\n ModelFieldType[\"Integer\"] = \"Int\";\n ModelFieldType[\"Float\"] = \"Float\";\n ModelFieldType[\"Boolean\"] = \"Boolean\";\n ModelFieldType[\"Date\"] = \"AWSDate\";\n ModelFieldType[\"Time\"] = \"AWSTime\";\n ModelFieldType[\"DateTime\"] = \"AWSDateTime\";\n ModelFieldType[\"Timestamp\"] = \"AWSTimestamp\";\n ModelFieldType[\"Email\"] = \"AWSEmail\";\n ModelFieldType[\"JSON\"] = \"AWSJSON\";\n ModelFieldType[\"Phone\"] = \"AWSPhone\";\n ModelFieldType[\"Url\"] = \"AWSURL\";\n ModelFieldType[\"IPAddress\"] = \"AWSIPAddress\";\n})(ModelFieldType || (ModelFieldType = {}));\nexport var ModelFieldDataType;\n(function (ModelFieldDataType) {\n ModelFieldDataType[\"String\"] = \"string\";\n ModelFieldDataType[\"Number\"] = \"number\";\n ModelFieldDataType[\"Boolean\"] = \"boolean\";\n ModelFieldDataType[\"Date\"] = \"Date\";\n ModelFieldDataType[\"JSON\"] = \"any\";\n})(ModelFieldDataType || (ModelFieldDataType = {}));\n/**\n * Model Field Implementation\n *\n * @typeParam T - holds the JS data type of the field; invoking the public methods changes this type accordingly\n * @example\n * string() => T = string | null\n * string().array() => T = Array<string | null> | null\n * string().array().required() => T = Array<string | null>\n * string().required().array().required() => T = Array<string>\n *\n * @param fieldType - stores the GraphQL data type of the field\n */\nfunction _field(fieldType) {\n const _meta = {\n lastInvokedMethod: null,\n };\n const data = {\n fieldType,\n required: false,\n array: false,\n arrayRequired: false,\n default: undefined,\n authorization: [],\n validation: [],\n };\n const builder = {\n required() {\n if (_meta.lastInvokedMethod === 'array') {\n data.arrayRequired = true;\n }\n else {\n data.required = true;\n }\n _meta.lastInvokedMethod = 'required';\n return this;\n },\n array() {\n data.array = true;\n _meta.lastInvokedMethod = 'array';\n return this;\n },\n default(val) {\n data.default = typeof val === 'undefined' ? __generated : val;\n _meta.lastInvokedMethod = 'default';\n return this;\n },\n authorization(callback) {\n const { resource: _, ...rest } = allow;\n const rules = callback(rest);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n _meta.lastInvokedMethod = 'authorization';\n return this;\n },\n validate(callback) {\n const { builder, getRules } = createValidationBuilder();\n callback(builder);\n data.validation = getRules();\n _meta.lastInvokedMethod = 'validate';\n return this;\n },\n ...brand(brandName),\n [internal]() {\n return this;\n },\n };\n return { ...builder, data };\n}\n/**\n * A unique identifier scalar type. This scalar is serialized like a String but isn't meant to be human-readable.\n * If not specified on create operations, a ULID will be auto-generated service-side.\n * @returns ID field definition\n */\nexport function id() {\n return _field(ModelFieldType.Id);\n}\n/**\n * A string scalar type that is represented server-side as a UTF-8 character sequence.\n * @returns string field definition\n */\nexport function string() {\n return _field(ModelFieldType.String);\n}\n/**\n * An integer scalar type with a supported value range between -(2^31) and 2^31-1.\n * @returns integer field definition\n */\nexport function integer() {\n return _field(ModelFieldType.Integer);\n}\n/**\n * A float scalar type following represented server-side as an IEEE 754 floating point value.\n * @returns float field definition\n */\nexport function float() {\n return _field(ModelFieldType.Float);\n}\n/**\n * A boolean scalar type that can be either true or false.\n * @returns boolean field definition\n */\nexport function boolean() {\n return _field(ModelFieldType.Boolean);\n}\n/**\n * A date scalar type that is represented server-side as an extended ISO 8601 date string in the format `YYYY-MM-DD`.\n * @returns date field definition\n */\nexport function date() {\n return _field(ModelFieldType.Date);\n}\n/**\n * A time scalar type that is represented server-side as an extended ISO 8601 time string in the format `hh:mm:ss.sss`.\n * @returns time field definition\n */\nexport function time() {\n return _field(ModelFieldType.Time);\n}\n/**\n * A date time scalar type that is represented server-side as an extended ISO 8601 date and time string in the format `YYYY-MM-DDThh:mm:ss.sssZ`.\n * @returns datetime field definition\n */\nexport function datetime() {\n return _field(ModelFieldType.DateTime);\n}\n/**\n * A timestamp scalar type that is represented by an integer value of the number of seconds before or after `1970-01-01-T00:00Z`.\n * @returns timestamp field definition\n */\nexport function timestamp() {\n return _field(ModelFieldType.Timestamp);\n}\n/**\n * An email scalar type that is represented server-side in the format `local-part@domain-part` as defined by RFC 822.\n * @returns email field definition\n */\nexport function email() {\n return _field(ModelFieldType.Email);\n}\n/**\n * A JSON scalar type that is automatically parsed and loaded server-side as maps, lists, or scalar values\n * rather than as the literal input strings.\n * @returns JSON field definition\n */\nexport function json() {\n return _field(ModelFieldType.JSON);\n}\n/**\n * A phone number scalar type thas is stored as a string server-side. Phone numbers can contain either spaces\n * or hyphens to separate digit groups. Phone numbers without a country code are assumed to be US/North American numbers adhering\n * to the North American Numbering Plan.\n * @returns phone number field definition\n */\nexport function phone() {\n return _field(ModelFieldType.Phone);\n}\n/**\n * A URL scalar type as defined by RFC 1738. For example, https://www.amazon.com/dp/B000NZW3KC/ or mailto:example@example.com.\n * URLs must contain a schema (http, mailto) and can't contain two forward slashes (//) in the path part.\n * @returns URL field definition\n */\nexport function url() {\n return _field(ModelFieldType.Url);\n}\n/**\n * A valid IPv4 or IPv6 address scalar type. IPv4 addresses are expected in quad-dotted notation (123.12.34.56). IPv6 addresses\n * are expected in non-bracketed, colon-separated format (1a2b:3c4b:🔢4567). You can include an optional CIDR suffix (123.45.67.89/16)\n * to indicate subnet mask.\n * @returns IP address field definition\n */\nexport function ipAddress() {\n return _field(ModelFieldType.IPAddress);\n}\n"],"names":[],"mappings":";;;;AAGA;AACA;AACA;AACY,MAAC,MAAM,GAAG,MAAM,CAAC,QAAQ;AACrC;AACA;AACA;AACY,MAAC,WAAW,GAAG,MAAM,CAAC,aAAa;AAC/C,MAAM,SAAS,GAAG,YAAY;AAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC;AACzB,IAAC;AACX,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;AAC/B,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,QAAQ;AACvC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,KAAK;AACrC,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO;AACrC,IAAI,cAAc,CAAC,SAAS,CAAC,GAAG,SAAS;AACzC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;AACtC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;AACtC,IAAI,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa;AAC9C,IAAI,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc;AAChD,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU;AACxC,IAAI,cAAc,CAAC,MAAM,CAAC,GAAG,SAAS;AACtC,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,UAAU;AACxC,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG,QAAQ;AACpC,IAAI,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc;AAChD,CAAC,EAAE,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ACA;AACA;AACA;AACA;AACO,SAAS,SAAS,GAAG;AAC5B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC;AAC3C;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelIndex.mjs","sources":["../../src/ModelIndex.ts"],"sourcesContent":["import { brand } from './util';\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n ...brand(brandName),\n };\n return { ...builder, data };\n}\nexport function modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,gBAAgB
|
|
1
|
+
{"version":3,"file":"ModelIndex.mjs","sources":["../../src/ModelIndex.ts"],"sourcesContent":["import { brand } from './util';\nconst brandName = 'modelIndexType';\nfunction _modelIndex(partitionKeyFieldName) {\n const data = {\n partitionKey: partitionKeyFieldName,\n sortKeys: [],\n indexName: '',\n queryField: '',\n };\n const builder = {\n sortKeys(sortKeys) {\n data.sortKeys = sortKeys;\n return this;\n },\n name(name) {\n data.indexName = name;\n return this;\n },\n queryField(field) {\n data.queryField = field;\n return this;\n },\n ...brand(brandName),\n };\n return { ...builder, data };\n}\nexport function modelIndex(partitionKeyFieldName) {\n return _modelIndex(partitionKeyFieldName);\n}\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,gBAAgB;AAClC,SAAS,WAAW,CAAC,qBAAqB,EAAE;AAC5C,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,YAAY,EAAE,qBAAqB;AAC3C,QAAQ,QAAQ,EAAE,EAAE;AACpB,QAAQ,SAAS,EAAE,EAAE;AACrB,QAAQ,UAAU,EAAE,EAAE;AACtB,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,QAAQ,CAAC,QAAQ,EAAE;AAC3B,YAAY,IAAI,CAAC,QAAQ,GAAG,QAAQ;AACpC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,IAAI,CAAC,IAAI,EAAE;AACnB,YAAY,IAAI,CAAC,SAAS,GAAG,IAAI;AACjC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,UAAU,CAAC,KAAK,EAAE;AAC1B,YAAY,IAAI,CAAC,UAAU,GAAG,KAAK;AACnC,YAAY,OAAO,IAAI;AACvB,SAAS;AACT,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC;AAC3B,KAAK;AACL,IAAI,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE;AAC/B;AACO,SAAS,UAAU,CAAC,qBAAqB,EAAE;AAClD,IAAI,OAAO,WAAW,CAAC,qBAAqB,CAAC;AAC7C;;;;"}
|