@scalar/mock-server 0.9.8 → 0.9.10
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/CHANGELOG.md +17 -0
- package/dist/create-mock-server.js +79 -68
- package/dist/index.js +1 -5
- package/dist/libs/store.js +66 -65
- package/dist/routes/mock-any-response.js +70 -63
- package/dist/routes/mock-handler-response.js +140 -100
- package/dist/routes/respond-with-authorize-page.js +89 -80
- package/dist/routes/respond-with-openapi-document.js +32 -35
- package/dist/routes/respond-with-token.js +40 -45
- package/dist/types.js +2 -5
- package/dist/utils/build-handler-context.js +83 -70
- package/dist/utils/build-seed-context.js +59 -52
- package/dist/utils/create-openapi-definition.js +7 -10
- package/dist/utils/execute-handler.js +16 -18
- package/dist/utils/execute-seed.js +22 -21
- package/dist/utils/find-preferred-response-key.js +9 -9
- package/dist/utils/get-open-auth-token-urls.js +45 -35
- package/dist/utils/get-operation.js +12 -12
- package/dist/utils/handle-authentication.js +106 -101
- package/dist/utils/hono-route-from-path.js +6 -6
- package/dist/utils/is-authentication-required.js +17 -15
- package/dist/utils/log-authentication-instructions.js +105 -110
- package/dist/utils/process-openapi-document.js +71 -58
- package/dist/utils/set-up-authentication-routes.js +80 -77
- package/dist/utils/store-wrapper.js +40 -39
- package/package.json +10 -14
- package/dist/create-mock-server.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/libs/store.js.map +0 -7
- package/dist/routes/mock-any-response.js.map +0 -7
- package/dist/routes/mock-handler-response.js.map +0 -7
- package/dist/routes/respond-with-authorize-page.js.map +0 -7
- package/dist/routes/respond-with-openapi-document.js.map +0 -7
- package/dist/routes/respond-with-token.js.map +0 -7
- package/dist/types.js.map +0 -7
- package/dist/utils/build-handler-context.js.map +0 -7
- package/dist/utils/build-seed-context.js.map +0 -7
- package/dist/utils/create-openapi-definition.js.map +0 -7
- package/dist/utils/execute-handler.js.map +0 -7
- package/dist/utils/execute-seed.js.map +0 -7
- package/dist/utils/find-preferred-response-key.js.map +0 -7
- package/dist/utils/get-open-auth-token-urls.js.map +0 -7
- package/dist/utils/get-operation.js.map +0 -7
- package/dist/utils/handle-authentication.js.map +0 -7
- package/dist/utils/hono-route-from-path.js.map +0 -7
- package/dist/utils/is-authentication-required.js.map +0 -7
- package/dist/utils/log-authentication-instructions.js.map +0 -7
- package/dist/utils/process-openapi-document.js.map +0 -7
- package/dist/utils/set-up-authentication-routes.js.map +0 -7
- package/dist/utils/store-wrapper.js.map +0 -7
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/log-authentication-instructions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport { getPathFromUrl } from './get-open-auth-token-urls'\n\n/**\n * Log authentication instructions for different security schemes\n */\nexport function logAuthenticationInstructions(securitySchemes: Record<string, OpenAPIV3_1.SecuritySchemeObject>) {\n if (!securitySchemes || Object.keys(securitySchemes).length === 0) {\n return\n }\n\n console.log('Authentication:')\n console.log()\n\n Object.entries(securitySchemes).forEach(([_, scheme]) => {\n switch (scheme.type) {\n case 'apiKey':\n if (scheme.in === 'header') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} header`)\n console.log()\n console.log(` ${scheme.name}: YOUR_API_KEY_HERE`)\n console.log()\n } else if (scheme.in === 'query') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} query parameter:`)\n console.log()\n console.log(` ?${scheme.name}=YOUR_API_KEY_HERE`)\n console.log()\n } else if (scheme.in === 'cookie') {\n console.log('\u2705 API Key Authentication')\n console.log(` Use any API key in the ${scheme.name} cookie:`)\n console.log()\n console.log(` Cookie: ${scheme.name}=YOUR_API_KEY_HERE`)\n console.log()\n } else {\n console.error(`\u274C Unsupported API Key Location: ${scheme.in}`)\n }\n break\n case 'http':\n if (scheme.scheme === 'basic') {\n console.log('\u2705 HTTP Basic Authentication')\n console.log(' Use an Authorization header with any credentials (\"username:password\" in base64):')\n console.log()\n console.log(' Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=')\n console.log()\n } else if (scheme.scheme === 'bearer') {\n console.log('\u2705 Bearer Token Authentication')\n console.log(' Use an Authorization header with any bearer token')\n console.log()\n console.log(' Authorization: Bearer YOUR_TOKEN_HERE')\n console.log()\n } else {\n console.error('\u274C Unknown Security Scheme:', scheme)\n }\n\n break\n case 'oauth2':\n if (scheme.flows) {\n Object.keys(scheme.flows).forEach((flow) => {\n switch (flow) {\n case 'implicit':\n console.log('\u2705 OAuth 2.0 Implicit Flow')\n console.log(' Use the following URL to initiate the OAuth 2.0 Implicit Flow:')\n console.log()\n console.log(\n ` GET ${scheme?.flows?.implicit?.authorizationUrl || '/oauth/authorize'}?response_type=token&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&scope=YOUR_SCOPES`,\n )\n console.log()\n break\n case 'password':\n console.log('\u2705 OAuth 2.0 Password Flow')\n console.log(' Use the following URL to obtain an access token:')\n console.log()\n console.log(` POST ${getPathFromUrl(scheme?.flows?.password?.tokenUrl || '/oauth/token')}`)\n console.log(' Content-Type: application/x-www-form-urlencoded')\n console.log()\n console.log(\n ' grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET',\n )\n console.log()\n break\n case 'clientCredentials':\n console.log('\u2705 OAuth 2.0 Client Credentials Flow')\n console.log(' Use the following URL to obtain an access token:')\n console.log()\n console.log(` POST ${getPathFromUrl(scheme?.flows?.clientCredentials?.tokenUrl || '/oauth/token')}`)\n console.log(' Content-Type: application/x-www-form-urlencoded')\n console.log()\n console.log(\n ' grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET',\n )\n console.log()\n break\n case 'authorizationCode':\n console.log('\u2705 OAuth 2.0 Authorization Code Flow')\n console.log(' Use the following URL to initiate the OAuth 2.0 Authorization Code Flow:')\n console.log()\n console.log(\n ' GET',\n `${getPathFromUrl(scheme?.flows?.authorizationCode?.authorizationUrl || '/oauth/authorize')}?redirect_uri=https://YOUR_REDIRECT_URI_HERE`,\n )\n console.log()\n break\n default:\n console.warn(`Unsupported OAuth 2.0 flow: ${flow}`)\n }\n })\n }\n break\n case 'openIdConnect':\n console.log('\u2705 OpenID Connect Authentication')\n console.log(' Use the following OpenID Connect discovery URL:')\n console.log()\n console.log(` ${getPathFromUrl(scheme.openIdConnectUrl || '/.well-known/openid-configuration')}`)\n console.log()\n break\n default:\n console.warn(`Unsupported security scheme type: ${scheme.type}`)\n }\n })\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,sBAAsB;AAKxB,SAAS,8BAA8B,iBAAmE;AAC/G,MAAI,CAAC,mBAAmB,OAAO,KAAK,eAAe,EAAE,WAAW,GAAG;AACjE;AAAA,EACF;AAEA,UAAQ,IAAI,iBAAiB;AAC7B,UAAQ,IAAI;AAEZ,SAAO,QAAQ,eAAe,EAAE,QAAQ,CAAC,CAAC,GAAG,MAAM,MAAM;AACvD,YAAQ,OAAO,MAAM;AAAA,MACnB,KAAK;AACH,YAAI,OAAO,OAAO,UAAU;AAC1B,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,SAAS;AAC7D,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,MAAM,OAAO,IAAI,qBAAqB;AAClD,kBAAQ,IAAI;AAAA,QACd,WAAW,OAAO,OAAO,SAAS;AAChC,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,mBAAmB;AACvE,kBAAQ,IAAI;AACZ,kBAAQ,IAAI,OAAO,OAAO,IAAI,oBAAoB;AAClD,kBAAQ,IAAI;AAAA,QACd,WAAW,OAAO,OAAO,UAAU;AACjC,kBAAQ,IAAI,+BAA0B;AACtC,kBAAQ,IAAI,6BAA6B,OAAO,IAAI,UAA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ACjD,wBAAQ,IAAI,qDAAqD;AACjE,wBAAQ,IAAI;AACZ,wBAAQ,IAAI,WAAW,eAAe,QAAQ,OAAO,mBAAmB,YAAY,cAAc,CAAC,EAAE;AACrG,wBAAQ,IAAI,oDAAoD;AAChE,wBAAQ,IAAI;AACZ,wBAAQ;AAAA,kBACN;AAAA,gBACF;AACA,wBAAQ,IAAI;AACZ;AAAA,cACF,KAAK;AACH,wBAAQ,IAAI,0CAAqC;AACjD,wBAAQ,IAAI,6EAA6E;AACzF,wBAAQ,IAAI;AACZ,wBAAQ;AAAA,kBACN;AAAA,kBACA,GAAG,eAAe,QAAQ,OAAO,mBAAmB,oBAAoB,kBAAkB,CAAC;AAAA,gBAC7F;AACA,wBAAQ,IAAI;AACZ;AAAA,cACF;AACE,wBAAQ,KAAK,+BAA+B,IAAI,EAAE;AAAA,YACtD;AAAA,UACF,CAAC;AAAA,QACH;AACA;AAAA,MACF,KAAK;AACH,gBAAQ,IAAI,sCAAiC;AAC7C,gBAAQ,IAAI,oDAAoD;AAChE,gBAAQ,IAAI;AACZ,gBAAQ,IAAI,MAAM,eAAe,OAAO,oBAAoB,mCAAmC,CAAC,EAAE;AAClG,gBAAQ,IAAI;AACZ;AAAA,MACF;AACE,gBAAQ,KAAK,qCAAqC,OAAO,IAAI,EAAE;AAAA,IACnE;AAAA,EACF,CAAC;AACH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/process-openapi-document.ts"],
|
|
4
|
-
"sourcesContent": ["import { bundle } from '@scalar/json-magic/bundle'\nimport { parseJson } from '@scalar/json-magic/bundle/plugins/node'\nimport { parseYaml } from '@scalar/json-magic/bundle/plugins/node'\nimport { readFiles } from '@scalar/json-magic/bundle/plugins/node'\nimport { fetchUrls } from '@scalar/json-magic/bundle/plugins/node'\nimport { dereference } from '@scalar/openapi-parser'\nimport type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport { upgrade } from '@scalar/openapi-upgrader'\n\n/**\n * Processes an OpenAPI document by bundling external references, upgrading to OpenAPI 3.1,\n * and dereferencing the document.\n *\n * @param document - The OpenAPI document to process. Can be a string (URL/path) or an object.\n * @returns A promise that resolves to the dereferenced OpenAPI 3.1 document.\n * @throws Error if the document cannot be processed or is invalid.\n */\nexport async function processOpenApiDocument(\n document: string | Record<string, any> | undefined,\n): Promise<OpenAPIV3_1.Document> {\n // Handle empty/undefined input gracefully\n if (!document || (typeof document === 'object' && Object.keys(document).length === 0)) {\n // Return a minimal valid OpenAPI 3.1 document\n return {\n openapi: '3.1.0',\n info: {\n title: 'Mock API',\n version: '1.0.0',\n },\n paths: {},\n }\n }\n\n let bundled: Record<string, any>\n\n try {\n // Bundle external references with Node.js plugins\n // Include parseJson and parseYaml to handle string inputs\n bundled = await bundle(document, {\n plugins: [parseJson(), parseYaml(), readFiles(), fetchUrls()],\n treeShake: false,\n })\n } catch (error) {\n throw new Error(`Failed to bundle OpenAPI document: ${error instanceof Error ? error.message : String(error)}`)\n }\n\n if (!bundled || typeof bundled !== 'object') {\n throw new Error('Bundled document is invalid: expected an object')\n }\n\n let upgraded: OpenAPIV3_1.Document\n\n try {\n // Upgrade to OpenAPI 3.1\n upgraded = upgrade(bundled, '3.1')\n } catch (error) {\n throw new Error(\n `Failed to upgrade OpenAPI document to 3.1: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n\n if (!upgraded) {\n throw new Error('Upgraded document is invalid: upgrade returned null or undefined')\n }\n\n // Dereference the document\n const dereferenceResult = dereference(upgraded)\n\n // Check for dereference errors\n if (dereferenceResult.errors && dereferenceResult.errors.length > 0) {\n const errorMessages = dereferenceResult.errors.map((err) => err.message).join(', ')\n throw new Error(`Failed to dereference OpenAPI document: ${errorMessages}`)\n }\n\n // Extract the schema from the dereference result\n const schema = dereferenceResult.schema\n\n if (!schema) {\n throw new Error('Dereference result does not contain a schema')\n }\n\n // Ensure the schema is a valid OpenAPI 3.1 document\n if (typeof schema !== 'object') {\n throw new Error('Dereferenced schema is invalid: expected an object')\n }\n\n return schema as OpenAPIV3_1.Document\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAE5B,SAAS,eAAe;AAUxB,eAAsB,uBACpB,UAC+B;AAE/B,MAAI,CAAC,YAAa,OAAO,aAAa,YAAY,OAAO,KAAK,QAAQ,EAAE,WAAW,GAAI;AAErF,WAAO;AAAA,MACL,SAAS;AAAA,MACT,MAAM;AAAA,QACJ,OAAO;AAAA,QACP,SAAS;AAAA,MACX;AAAA,MACA,OAAO,CAAC;AAAA,IACV;AAAA,EACF;AAEA,MAAI;AAEJ,MAAI;AAGF,cAAU,MAAM,OAAO,UAAU;AAAA,MAC/B,SAAS,CAAC,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAAA,MAC5D,WAAW;AAAA,IACb,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,sCAAsC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AAAA,EAChH;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AAEA,MAAI;AAEJ,MAAI;AAEF,eAAW,QAAQ,SAAS,KAAK;AAAA,EACnC,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,8CAA8C,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IACtG;AAAA,EACF;AAEA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AAGA,QAAM,oBAAoB,YAAY,QAAQ;AAG9C,MAAI,kBAAkB,UAAU,kBAAkB,OAAO,SAAS,GAAG;AACnE,UAAM,gBAAgB,kBAAkB,OAAO,IAAI,CAAC,QAAQ,IAAI,OAAO,EAAE,KAAK,IAAI;AAClF,UAAM,IAAI,MAAM,2CAA2C,aAAa,EAAE;AAAA,EAC5E;AAGA,QAAM,SAAS,kBAAkB;AAEjC,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAGA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AAEA,SAAO;AACT;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/set-up-authentication-routes.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPI, OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { Hono } from 'hono'\n\nimport { respondWithAuthorizePage } from '@/routes/respond-with-authorize-page'\nimport { respondWithToken } from '@/routes/respond-with-token'\n\nimport { getOpenAuthTokenUrls, getPathFromUrl } from './get-open-auth-token-urls'\n\n/**\n * Helper function to set up authentication routes for OAuth 2.0 flows\n */\nexport function setUpAuthenticationRoutes(app: Hono, schema?: OpenAPI.Document) {\n const securitySchemes: Record<string, OpenAPIV3.SecuritySchemeObject | OpenAPIV3_1.SecuritySchemeObject> =\n schema?.components?.securitySchemes || {}\n\n // Set up authentication routes for OAuth 2.0 flows\n getOpenAuthTokenUrls(schema).forEach((tokenUrl) => {\n app.post(tokenUrl, (c) => {\n return c.json(\n {\n access_token: 'super-secret-access-token',\n token_type: 'Bearer',\n expires_in: 3600,\n refresh_token: 'example-refresh-token',\n },\n 200,\n {\n /**\n * When responding with an access token, the server must also include the additional\n * Cache-Control: no-store HTTP header to ensure clients do not cache this request.\n *\n * @see https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/\n */\n 'Cache-Control': 'no-store',\n },\n )\n })\n })\n\n // Set up routes for different OAuth 2.0 flows\n const authorizeUrls = new Set<string>()\n const tokenUrls = new Set<string>()\n\n Object.entries(securitySchemes).forEach(([_, scheme]) => {\n if (scheme.type === 'oauth2') {\n if (scheme.flows?.authorizationCode) {\n const authorizeRoute = scheme.flows.authorizationCode.authorizationUrl ?? '/oauth/authorize'\n const tokenRoute = scheme.flows.authorizationCode.tokenUrl ?? '/oauth/token'\n\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n tokenUrls.add(tokenRoute)\n }\n\n if (scheme.flows?.implicit) {\n const authorizeRoute = scheme.flows.implicit.authorizationUrl ?? '/oauth/authorize'\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n }\n\n if (scheme.flows?.password) {\n const tokenRoute = scheme.flows.password.tokenUrl ?? '/oauth/token'\n tokenUrls.add(tokenRoute)\n }\n\n if (scheme.flows?.clientCredentials) {\n const tokenRoute = scheme.flows.clientCredentials.tokenUrl ?? '/oauth/token'\n tokenUrls.add(tokenRoute)\n }\n } else if (scheme.type === 'openIdConnect') {\n // Handle OpenID Connect configuration\n if (scheme.openIdConnectUrl) {\n const configPath = getPathFromUrl(scheme.openIdConnectUrl ?? '/.well-known/openid-configuration')\n\n // Add route for OpenID Connect configuration\n app.get(configPath, (c) => {\n return c.json({\n issuer: 'https://example.com',\n authorization_endpoint: '/oauth/authorize',\n token_endpoint: '/oauth/token',\n response_types_supported: ['code', 'token', 'id_token'],\n subject_types_supported: ['public'],\n id_token_signing_alg_values_supported: ['RS256'],\n })\n })\n\n // Add standard endpoints\n const authorizeRoute = '/oauth/authorize'\n const tokenRoute = '/oauth/token'\n\n authorizeUrls.add(getPathFromUrl(authorizeRoute))\n tokenUrls.add(tokenRoute)\n }\n }\n })\n\n // Set up unique authorization routes\n authorizeUrls.forEach((authorizeUrl) => {\n app.get(authorizeUrl, (c) => respondWithAuthorizePage(c, schema?.info?.title))\n })\n\n // Set up unique token routes\n tokenUrls.forEach((tokenUrl) => {\n app.post(tokenUrl, respondWithToken)\n })\n}\n"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AA,IACF,WAAW,OAAO,SAAS,iBAAiB;AAE1C,UAAI,OAAO,kBAAkB;AAC3B,cAAM,aAAa,eAAe,OAAO,oBAAoB,mCAAmC;AAGhG,YAAI,IAAI,YAAY,CAAC,MAAM;AACzB,iBAAO,EAAE,KAAK;AAAA,YACZ,QAAQ;AAAA,YACR,wBAAwB;AAAA,YACxB,gBAAgB;AAAA,YAChB,0BAA0B,CAAC,QAAQ,SAAS,UAAU;AAAA,YACtD,yBAAyB,CAAC,QAAQ;AAAA,YAClC,uCAAuC,CAAC,OAAO;AAAA,UACjD,CAAC;AAAA,QACH,CAAC;AAGD,cAAM,iBAAiB;AACvB,cAAM,aAAa;AAEnB,sBAAc,IAAI,eAAe,cAAc,CAAC;AAChD,kBAAU,IAAI,UAAU;AAAA,MAC1B;AAAA,IACF;AAAA,EACF,CAAC;AAGD,gBAAc,QAAQ,CAAC,iBAAiB;AACtC,QAAI,IAAI,cAAc,CAAC,MAAM,yBAAyB,GAAG,QAAQ,MAAM,KAAK,CAAC;AAAA,EAC/E,CAAC;AAGD,YAAU,QAAQ,CAAC,aAAa;AAC9B,QAAI,KAAK,UAAU,gBAAgB;AAAA,EACrC,CAAC;AACH;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/store-wrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Store } from '../libs/store'\n\n/**\n * Public interface of the Store class (methods only, no private properties).\n */\ntype StoreInterface = Pick<Store, 'list' | 'get' | 'create' | 'update' | 'delete' | 'clear'>\n\n/**\n * Represents a single store operation with its result.\n */\ntype StoreOperation = {\n /** The operation method name that was called. */\n operation: 'get' | 'create' | 'update' | 'delete' | 'list'\n /** The result of the operation. */\n result: any\n}\n\n/**\n * Tracks all store operations performed.\n */\nexport type StoreOperationTracking = {\n /** All operations performed, in order. */\n operations: StoreOperation[]\n}\n\n/**\n * Creates a wrapped store that tracks operations.\n * Returns both the wrapped store and a tracking object that gets updated as operations are performed.\n */\nexport function createStoreWrapper(store: Store): {\n wrappedStore: StoreInterface\n tracking: StoreOperationTracking\n} {\n const tracking: StoreOperationTracking = {\n operations: [],\n }\n\n const wrappedStore = {\n list(collection: string) {\n const result = store.list(collection)\n tracking.operations.push({ operation: 'list', result })\n return result\n },\n\n get(collection: string, id: string) {\n const result = store.get(collection, id)\n tracking.operations.push({ operation: 'get', result })\n return result\n },\n\n create(collection: string, data: any) {\n const result = store.create(collection, data)\n tracking.operations.push({ operation: 'create', result })\n return result\n },\n\n update(collection: string, id: string, data: any) {\n const result = store.update(collection, id, data)\n tracking.operations.push({ operation: 'update', result })\n return result\n },\n\n delete(collection: string, id: string) {\n const result = store.delete(collection, id)\n tracking.operations.push({ operation: 'delete', result })\n return result\n },\n\n clear(collection?: string) {\n store.clear(collection)\n // clear() doesn't set tracking as it's not a typical CRUD operation\n },\n }\n\n return { wrappedStore, tracking }\n}\n"],
|
|
5
|
-
"mappings": "AA6BO,SAAS,mBAAmB,OAGjC;AACA,QAAM,WAAmC;AAAA,IACvC,YAAY,CAAC;AAAA,EACf;AAEA,QAAM,eAAe;AAAA,IACnB,KAAK,YAAoB;AACvB,YAAM,SAAS,MAAM,KAAK,UAAU;AACpC,eAAS,WAAW,KAAK,EAAE,WAAW,QAAQ,OAAO,CAAC;AACtD,aAAO;AAAA,IACT;AAAA,IAEA,IAAI,YAAoB,IAAY;AAClC,YAAM,SAAS,MAAM,IAAI,YAAY,EAAE;AACvC,eAAS,WAAW,KAAK,EAAE,WAAW,OAAO,OAAO,CAAC;AACrD,aAAO;AAAA,IACT;AAAA,IAEA,OAAO,YAAoB,MAAW;AACpC,YAAM,SAAS,MAAM,OAAO,YAAY,IAAI;AAC5C,eAAS,WAAW,KAAK,EAAE,WAAW,UAAU,OAAO,CAAC;AACxD,aAAO;AAAA,IACT;AAAA,IAEA,OAAO,YAAoB,IAAY,MAAW;AAChD,YAAM,SAAS,MAAM,OAAO,YAAY,IAAI,IAAI;AAChD,eAAS,WAAW,KAAK,EAAE,WAAW,UAAU,OAAO,CAAC;AACxD,aAAO;AAAA,IACT;AAAA,IAEA,OAAO,YAAoB,IAAY;AACrC,YAAM,SAAS,MAAM,OAAO,YAAY,EAAE;AAC1C,eAAS,WAAW,KAAK,EAAE,WAAW,UAAU,OAAO,CAAC;AACxD,aAAO;AAAA,IACT;AAAA,IAEA,MAAM,YAAqB;AACzB,YAAM,MAAM,UAAU;AAAA,IAExB;AAAA,EACF;AAEA,SAAO,EAAE,cAAc,SAAS;AAClC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|