@warp-drive/utilities 5.9.0-alpha.2 → 5.9.0-alpha.21
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/cjs-dist/string.cjs +448 -0
- package/cjs-dist/string.cjs.map +1 -0
- package/declarations/-private.d.ts +12 -1
- package/declarations/-private.d.ts.map +1 -0
- package/declarations/active-record.d.ts +260 -3
- package/declarations/active-record.d.ts.map +1 -0
- package/declarations/derivations.d.ts +26 -23
- package/declarations/derivations.d.ts.map +1 -0
- package/declarations/handlers.d.ts +282 -9
- package/declarations/handlers.d.ts.map +1 -0
- package/declarations/index-BeMAuqgZ.d.ts +462 -0
- package/declarations/index-BeMAuqgZ.d.ts.map +1 -0
- package/declarations/index.d.ts +2 -208
- package/declarations/json-api.d.ts +496 -5
- package/declarations/json-api.d.ts.map +1 -0
- package/declarations/rest.d.ts +258 -3
- package/declarations/rest.d.ts.map +1 -0
- package/declarations/string.d.ts +164 -13
- package/declarations/string.d.ts.map +1 -0
- package/dist/-private.js +2 -6
- package/dist/active-record.js +254 -379
- package/dist/active-record.js.map +1 -0
- package/dist/builder-utils-BkXwUT0x.js +16 -0
- package/dist/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/derivations.js +26 -26
- package/dist/derivations.js.map +1 -0
- package/dist/handlers.js +240 -283
- package/dist/handlers.js.map +1 -0
- package/dist/index.js +357 -335
- package/dist/index.js.map +1 -0
- package/dist/inflections-DzBsjJqj.js +80 -0
- package/dist/inflections-DzBsjJqj.js.map +1 -0
- package/dist/json-api.js +470 -706
- package/dist/json-api.js.map +1 -0
- package/dist/rest.js +254 -377
- package/dist/rest.js.map +1 -0
- package/dist/string-CWmAluxh.js +290 -0
- package/dist/string-CWmAluxh.js.map +1 -0
- package/dist/string.js +2 -427
- package/dist/unpkg/dev/-private.js +2 -6
- package/dist/unpkg/dev/active-record.js +253 -378
- package/dist/unpkg/dev/active-record.js.map +1 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev/derivations.js +26 -26
- package/dist/unpkg/dev/derivations.js.map +1 -0
- package/dist/unpkg/dev/handlers.js +238 -282
- package/dist/unpkg/dev/handlers.js.map +1 -0
- package/dist/unpkg/dev/index.js +356 -336
- package/dist/unpkg/dev/index.js.map +1 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev/json-api.js +469 -706
- package/dist/unpkg/dev/json-api.js.map +1 -0
- package/dist/unpkg/dev/rest.js +253 -376
- package/dist/unpkg/dev/rest.js.map +1 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev/string.js +3 -1
- package/dist/unpkg/dev-deprecated/-private.js +2 -6
- package/dist/unpkg/dev-deprecated/active-record.js +253 -378
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/dev-deprecated/derivations.js +26 -26
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/dev-deprecated/handlers.js +238 -282
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +356 -336
- package/dist/unpkg/dev-deprecated/index.js.map +1 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/dev-deprecated/json-api.js +469 -706
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/dev-deprecated/rest.js +253 -376
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +3 -1
- package/dist/unpkg/prod/-private.js +2 -6
- package/dist/unpkg/prod/active-record.js +236 -351
- package/dist/unpkg/prod/active-record.js.map +1 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod/derivations.js +26 -26
- package/dist/unpkg/prod/derivations.js.map +1 -0
- package/dist/unpkg/prod/handlers.js +231 -272
- package/dist/unpkg/prod/handlers.js.map +1 -0
- package/dist/unpkg/prod/index.js +265 -215
- package/dist/unpkg/prod/index.js.map +1 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod/json-api.js +446 -669
- package/dist/unpkg/prod/json-api.js.map +1 -0
- package/dist/unpkg/prod/rest.js +236 -349
- package/dist/unpkg/prod/rest.js.map +1 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod/string.js +3 -1
- package/dist/unpkg/prod-deprecated/-private.js +2 -6
- package/dist/unpkg/prod-deprecated/active-record.js +236 -351
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
- package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
- package/dist/unpkg/prod-deprecated/derivations.js +26 -26
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
- package/dist/unpkg/prod-deprecated/handlers.js +231 -272
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +265 -215
- package/dist/unpkg/prod-deprecated/index.js.map +1 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
- package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/json-api.js +446 -669
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
- package/dist/unpkg/prod-deprecated/rest.js +236 -349
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +3 -1
- package/package.json +11 -10
- package/declarations/-private/active-record/find-record.d.ts +0 -64
- package/declarations/-private/active-record/query.d.ts +0 -53
- package/declarations/-private/active-record/save-record.d.ts +0 -146
- package/declarations/-private/builder-utils.d.ts +0 -4
- package/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/declarations/-private/handlers/gated.d.ts +0 -19
- package/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/declarations/-private/handlers/utils.d.ts +0 -41
- package/declarations/-private/json-api/-utils.d.ts +0 -109
- package/declarations/-private/json-api/find-record.d.ts +0 -84
- package/declarations/-private/json-api/query.d.ts +0 -100
- package/declarations/-private/json-api/save-record.d.ts +0 -228
- package/declarations/-private/json-api/serialize.d.ts +0 -70
- package/declarations/-private/rest/find-record.d.ts +0 -62
- package/declarations/-private/rest/query.d.ts +0 -53
- package/declarations/-private/rest/save-record.d.ts +0 -146
- package/declarations/-private/string/inflect.d.ts +0 -82
- package/declarations/-private/string/inflections.d.ts +0 -9
- package/declarations/-private/string/transform.d.ts +0 -77
- package/dist/builder-utils-Donkk-BZ.js +0 -22
- package/dist/inflect-BSG696t-.js +0 -344
- package/dist/string.cjs +0 -430
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
- package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-record.js","names":["recordIdentifierFor","buildBaseURL","pluralize","underscore","copyForwardUrlOptions","macroCondition","getGlobalConfig","isExisting","identifier","id","type","deleteRecord","record","options","WarpDrive","env","DEBUG","test","Error","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../src/-private/active-record/find-record.ts","../src/-private/active-record/query.ts","../src/-private/active-record/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive/core/types/request';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string.ts';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/active-record';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/active-record';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/active-record';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive/utilities/active-record';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param options\n */\nexport function findRecord<T>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord(\n arg1: string | RemotelyAccessibleIdentifier,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions {\n const identifier: RemotelyAccessibleIdentifier = typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options = ((typeof arg1 === 'string' ? arg3 : arg2) || {}) as FindRecordOptions;\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<T> = ReactiveDataDocument<T>;\n","import type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive/core/types/request';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/active-record';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/active-record';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and underscoring the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive/utilities/active-record';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[]>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(underscore(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive/core/types/request';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { pluralize, underscore } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/active-record';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive/utilities/active-record';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most ActiveRecord APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive/utilities/active-record';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(underscore(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n"],"mappings":";;;;;;;AAiFA,SAAgB,WACd,MACA,MACA,MAC0B;CAC1B,MAAM,aAA2C,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM,IAAI;CAAe,IAAI;CACjH,MAAM,WAAY,OAAO,SAAS,WAAW,OAAO,SAAS,CAAC;CAC9D,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAAmC;EACvC;EACA,IAAI;EACJ,cAAc,UAAU,WAAW,WAAW,IAAI,CAAC;CACrD;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACL,KAAK,QAAQ,SAAS,SAClB,GAAG,IAAI,GAAG,iBAAiB,EAAE,SAAS,QAAQ,QAAQ,GAAG,QAAQ,iBAAiB,MAClF;EACJ,QAAQ;EACR;EACA;EACA,IAAI;EACJ,SAAS,CAAC,UAAU;CACtB;AACF;;;;AC7CA,SAAgB,MACd,MAEA,QAA2B,CAAC,GAC5B,UAAqC,CAAC,GACjB;CACrB,MAAM,eAAe,oBAAoB,OAAO;C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ACrD;CAEAN,sBAAsBe,YAAYN,OAAO;CAEzC,MAAMS,MAAMrB,aAAakB,UAAU;CACnC,MAAMI,UAAU,IAAIC,QAAQ;CAC5BD,QAAQE,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACLH;EACAI,QAAQb,QAAQkB,QAAQ,UAAU;EAClCR;EACAH,IAAI;EACJO,MAAM,EACJf,QAAQJ,WACV;EACAoB,SAAS,CAACpB,UAAU;CACtB;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/-private/builder-utils.ts
|
|
2
|
+
function copyForwardUrlOptions(urlOptions, options) {
|
|
3
|
+
if ("host" in options) urlOptions.host = options.host;
|
|
4
|
+
if ("namespace" in options) urlOptions.namespace = options.namespace;
|
|
5
|
+
if ("resourcePath" in options) urlOptions.resourcePath = options.resourcePath;
|
|
6
|
+
}
|
|
7
|
+
function extractCacheOptions(options) {
|
|
8
|
+
const cacheOptions = {};
|
|
9
|
+
if ("reload" in options) cacheOptions.reload = options.reload;
|
|
10
|
+
if ("backgroundReload" in options) cacheOptions.backgroundReload = options.backgroundReload;
|
|
11
|
+
return cacheOptions;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { extractCacheOptions as n, copyForwardUrlOptions as t };
|
|
16
|
+
//# sourceMappingURL=builder-utils-BkXwUT0x.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-utils-BkXwUT0x.js","names":[],"sources":["../src/-private/builder-utils.ts"],"sourcesContent":["import type { CacheOptions, ConstrainedRequestOptions } from '@warp-drive/core/types/request';\n\nimport type { UrlOptions } from '../index.ts';\n\nexport function copyForwardUrlOptions(urlOptions: UrlOptions, options: ConstrainedRequestOptions): void {\n if ('host' in options) {\n urlOptions.host = options.host;\n }\n if ('namespace' in options) {\n urlOptions.namespace = options.namespace;\n }\n if ('resourcePath' in options) {\n urlOptions.resourcePath = options.resourcePath;\n }\n}\n\nexport function extractCacheOptions(options: ConstrainedRequestOptions): CacheOptions {\n const cacheOptions: CacheOptions = {};\n if ('reload' in options) {\n cacheOptions.reload = options.reload;\n }\n if ('backgroundReload' in options) {\n cacheOptions.backgroundReload = options.backgroundReload;\n }\n return cacheOptions;\n}\n"],"mappings":";AAIA,SAAgB,sBAAsB,YAAwB,SAA0C;CACtG,IAAI,UAAU,SACZ,WAAW,OAAO,QAAQ;CAE5B,IAAI,eAAe,SACjB,WAAW,YAAY,QAAQ;CAEjC,IAAI,kBAAkB,SACpB,WAAW,eAAe,QAAQ;AAEtC;AAEA,SAAgB,oBAAoB,SAAkD;CACpF,MAAM,eAA6B,CAAC;CACpC,IAAI,YAAY,SACd,aAAa,SAAS,QAAQ;CAEhC,IAAI,sBAAsB,SACxB,aAAa,mBAAmB,QAAQ;CAE1C,OAAO;AACT"}
|
package/dist/derivations.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { Type } from
|
|
1
|
+
import { Type } from "@warp-drive/core/types/symbols";
|
|
2
2
|
|
|
3
|
+
//#region src/derivations.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
* A derivation for use by {@link ReactiveResource} that joins the given fields
|
|
6
|
+
* with the optional separator (or '' if no separator is provided).
|
|
7
|
+
*
|
|
8
|
+
* Generally you should not need to import and use this function directly.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* {
|
|
12
|
+
* name: 'fullName',
|
|
13
|
+
* kind: 'derived',
|
|
14
|
+
* type: 'concat',
|
|
15
|
+
* options: {
|
|
16
|
+
* fields: ['firstName', 'lastName'],
|
|
17
|
+
* separator: ' ',
|
|
18
|
+
* },
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
20
21
|
const concat = (record, options, _prop) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// SAFETY: we cast internally to a more specific type, for our own use
|
|
25
|
-
// SAFETY: but provide the more general signature to the schema service
|
|
26
|
-
const opts = options;
|
|
27
|
-
return opts.fields.map(field => record[field]).join(opts.separator ?? '');
|
|
22
|
+
if (!options) throw new Error(`options is required`);
|
|
23
|
+
const opts = options;
|
|
24
|
+
return opts.fields.map((field) => record[field]).join(opts.separator ?? "");
|
|
28
25
|
};
|
|
29
|
-
concat[Type] =
|
|
30
|
-
|
|
26
|
+
concat[Type] = "concat";
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { concat };
|
|
30
|
+
//# sourceMappingURL=derivations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derivations.js","names":["Type","concat","record","options","_prop","Error","opts","fields","map","field","join","separator"],"sources":["../src/derivations.ts"],"sourcesContent":["import type { ReactiveResource } from '@warp-drive/core/reactive';\nimport { Type } from '@warp-drive/core/types/symbols';\n\ninterface ConcatDerivation {\n (\n record: ReactiveResource & { [key: string]: unknown },\n options: Record<string, unknown> | null,\n _prop: string\n ): string;\n [Type]: 'concat';\n}\n\n/**\n * A derivation for use by {@link ReactiveResource} that joins the given fields\n * with the optional separator (or '' if no separator is provided).\n *\n * Generally you should not need to import and use this function directly.\n *\n * @example\n * {\n * name: 'fullName',\n * kind: 'derived',\n * type: 'concat',\n * options: {\n * fields: ['firstName', 'lastName'],\n * separator: ' ',\n * },\n * }\n */\nexport const concat: ConcatDerivation = (\n record: ReactiveResource & { [key: string]: unknown },\n options: Record<string, unknown> | null,\n _prop: string\n) => {\n if (!options) {\n throw new Error(`options is required`);\n }\n // SAFETY: we cast internally to a more specific type, for our own use\n // SAFETY: but provide the more general signature to the schema service\n const opts = options as { fields: string[]; separator?: string };\n return opts.fields.map((field) => record[field]).join(opts.separator ?? '');\n};\nconcat[Type] = 'concat';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6BA,MAAaC,UACXC,QACAC,SACAC,UACG;CACH,IAAI,CAACD,SACH,MAAM,IAAIE,MAAM,qBAAqB;CAIvC,MAAMC,OAAOH;CACb,OAAOG,KAAKC,OAAOC,KAAKC,UAAUP,OAAOO,MAAM,CAAC,CAACC,KAAKJ,KAAKK,aAAa,EAAE;AAC5E;AACAV,OAAOD,QAAQ"}
|