@signalium/query 1.0.17 → 1.1.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/CHANGELOG.md +47 -0
- package/dist/cjs/development/index.js +52 -15
- package/dist/cjs/development/index.js.map +1 -1
- package/dist/cjs/production/index.js +52 -15
- package/dist/cjs/production/index.js.map +1 -1
- package/dist/esm/EntityMap.d.ts.map +1 -1
- package/dist/esm/QueryClient.d.ts +3 -2
- package/dist/esm/QueryClient.d.ts.map +1 -1
- package/dist/esm/development/index.js +52 -15
- package/dist/esm/development/index.js.map +1 -1
- package/dist/esm/mutation.d.ts.map +1 -1
- package/dist/esm/pathInterpolator.d.ts +7 -3
- package/dist/esm/pathInterpolator.d.ts.map +1 -1
- package/dist/esm/production/index.js +52 -15
- package/dist/esm/production/index.js.map +1 -1
- package/dist/esm/query.d.ts +14 -8
- package/dist/esm/query.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../../src/mutation.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,UAAU,EAEV,kBAAkB,EAElB,8BAA8B,EAE9B,OAAO,EACP,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAsB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKpE,KAAK,WAAW,CAAC,IAAI,IAAI,IAAI,SAAS,IAAI,MAAM,SAAS,GAAG,GAAG,SAAS,GAAG,KAAK,CAAC;AACjF,KAAK,aAAa,CAAC,IAAI,IAAI,IAAI,SAAS,GAAG,MAAM,KAAK,IAAI,MAAM,KAAK,EAAE,GACnE,WAAW,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GACzC,WAAW,CAAC,IAAI,CAAC,CAAC;AACtB,KAAK,UAAU,CAAC,GAAG,IAAI,GAAG,SAAS,MAAM,MAAM,QAAQ,EAAE,GAAG,CAAC,MAAM,GAAG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8BAA8B,CAAC,UAAU,CAAC,CAAC;AAiHlE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,QAAQ,CACtB,IAAI,SAAS,MAAM,EACnB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,kBAAkB,EAC1E,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,kBAAkB,EAE3E,yBAAyB,EAAE,MAAM,sBAAsB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,GACrF,UAAU,CAAC,sBAAsB,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,WAAW,CAAC,CAEnE"}
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* keys, then uses simple string concatenation at runtime for optimal performance.
|
|
9
9
|
*/
|
|
10
10
|
export type PathInterpolator = (params: Record<string, any>) => string;
|
|
11
|
+
export interface PathInterpolatorResult {
|
|
12
|
+
interpolate: PathInterpolator;
|
|
13
|
+
pathParamNames: Set<string>;
|
|
14
|
+
}
|
|
11
15
|
/**
|
|
12
16
|
* Creates an optimized path interpolation function from a URL template.
|
|
13
17
|
*
|
|
@@ -16,14 +20,14 @@ export type PathInterpolator = (params: Record<string, any>) => string;
|
|
|
16
20
|
* found in the path template are appended as query string parameters.
|
|
17
21
|
*
|
|
18
22
|
* @param pathTemplate - URL template with {paramName} placeholders
|
|
19
|
-
* @returns
|
|
23
|
+
* @returns Object with interpolate function and set of path param names
|
|
20
24
|
*
|
|
21
25
|
* @example
|
|
22
26
|
* ```ts
|
|
23
|
-
* const interpolate = createPathInterpolator('/users/{userId}/posts/{postId}');
|
|
27
|
+
* const { interpolate } = createPathInterpolator('/users/{userId}/posts/{postId}');
|
|
24
28
|
* const url = interpolate({ userId: '123', postId: '456', page: 2, limit: 10 });
|
|
25
29
|
* // Returns: "/users/123/posts/456?page=2&limit=10"
|
|
26
30
|
* ```
|
|
27
31
|
*/
|
|
28
|
-
export declare function createPathInterpolator(pathTemplate: string):
|
|
32
|
+
export declare function createPathInterpolator(pathTemplate: string): PathInterpolatorResult;
|
|
29
33
|
//# sourceMappingURL=pathInterpolator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathInterpolator.d.ts","sourceRoot":"","sources":["../../src/pathInterpolator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;AAEvE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"pathInterpolator.d.ts","sourceRoot":"","sources":["../../src/pathInterpolator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;AAEvE,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,gBAAgB,CAAC;IAC9B,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,sBAAsB,CA8CnF"}
|
|
@@ -1137,7 +1137,8 @@ class EntityStore {
|
|
|
1137
1137
|
});
|
|
1138
1138
|
}
|
|
1139
1139
|
const warn = this.queryClient.getContext().log?.warn;
|
|
1140
|
-
|
|
1140
|
+
const desc = `${shape.typenameValue}:${id}`;
|
|
1141
|
+
return createEntityProxy(record.key, record, shape, entityRelay, this.queryClient, warn, desc);
|
|
1141
1142
|
}
|
|
1142
1143
|
}
|
|
1143
1144
|
class NetworkManager {
|
|
@@ -1329,7 +1330,7 @@ function parseObjectEntities(obj, objectShape, queryClient, entityRefs) {
|
|
|
1329
1330
|
throw new Error(`Entity id is required: ${typename}`);
|
|
1330
1331
|
}
|
|
1331
1332
|
const desc = `${typename}:${id}`;
|
|
1332
|
-
const key = hashValue(desc);
|
|
1333
|
+
const key = hashValue([desc, entityDef.shapeKey]);
|
|
1333
1334
|
if (entityRefs !== void 0) {
|
|
1334
1335
|
entityRefs.add(key);
|
|
1335
1336
|
}
|
|
@@ -2348,7 +2349,7 @@ class MutationResultImpl {
|
|
|
2348
2349
|
const entityId = obj[idField];
|
|
2349
2350
|
if (entityId !== void 0) {
|
|
2350
2351
|
const typename = entityDef.typenameValue;
|
|
2351
|
-
const entityKey = hashValue(`${typename}:${entityId}
|
|
2352
|
+
const entityKey = hashValue([`${typename}:${entityId}`, entityDef.shapeKey]);
|
|
2352
2353
|
this.queryClient.registerOptimisticUpdate(entityKey, obj);
|
|
2353
2354
|
this._pendingOptimisticKeys.add(entityKey);
|
|
2354
2355
|
}
|
|
@@ -2559,7 +2560,7 @@ var QueryType = /* @__PURE__ */ ((QueryType2) => {
|
|
|
2559
2560
|
return QueryType2;
|
|
2560
2561
|
})(QueryType || {});
|
|
2561
2562
|
function isSignal(value) {
|
|
2562
|
-
return typeof value === "object" && value !== null;
|
|
2563
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && "value" in value && "_id" in value;
|
|
2563
2564
|
}
|
|
2564
2565
|
function extractParamsForKey(params) {
|
|
2565
2566
|
if (params === void 0) {
|
|
@@ -2703,7 +2704,7 @@ function createPathInterpolator(pathTemplate) {
|
|
|
2703
2704
|
lastIndex = paramRegex.lastIndex;
|
|
2704
2705
|
}
|
|
2705
2706
|
segments.push(pathTemplate.slice(lastIndex));
|
|
2706
|
-
|
|
2707
|
+
const interpolate = (params) => {
|
|
2707
2708
|
let result = segments[0];
|
|
2708
2709
|
for (let i = 0; i < paramKeys.length; i++) {
|
|
2709
2710
|
result += encodeURIComponent(String(params[paramKeys[i]])) + segments[i + 1];
|
|
@@ -2722,6 +2723,7 @@ function createPathInterpolator(pathTemplate) {
|
|
|
2722
2723
|
}
|
|
2723
2724
|
return result;
|
|
2724
2725
|
};
|
|
2726
|
+
return { interpolate, pathParamNames: paramKeysSet };
|
|
2725
2727
|
}
|
|
2726
2728
|
const QUERY_DEFINITION_MAP = /* @__PURE__ */ new Map();
|
|
2727
2729
|
function buildQueryFn(queryDefinitionBuilder) {
|
|
@@ -2731,6 +2733,8 @@ function buildQueryFn(queryDefinitionBuilder) {
|
|
|
2731
2733
|
const {
|
|
2732
2734
|
path,
|
|
2733
2735
|
method = "GET",
|
|
2736
|
+
searchParams,
|
|
2737
|
+
body,
|
|
2734
2738
|
response,
|
|
2735
2739
|
requestOptions,
|
|
2736
2740
|
cache,
|
|
@@ -2757,14 +2761,53 @@ function buildQueryFn(queryDefinitionBuilder) {
|
|
|
2757
2761
|
shape = response;
|
|
2758
2762
|
shapeKey = hashValue(shape);
|
|
2759
2763
|
}
|
|
2760
|
-
const interpolatePath = createPathInterpolator(path);
|
|
2764
|
+
const { interpolate: interpolatePath, pathParamNames } = createPathInterpolator(path);
|
|
2765
|
+
const bodyParamNames = /* @__PURE__ */ new Set();
|
|
2766
|
+
const hasBody = body !== void 0 && typeof body === "object" && !(body instanceof ValidatorDef) && !(body instanceof Set);
|
|
2767
|
+
if (hasBody) {
|
|
2768
|
+
for (const key of Object.keys(body)) {
|
|
2769
|
+
bodyParamNames.add(key);
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
const searchParamNames = new Set(
|
|
2773
|
+
searchParams && typeof searchParams === "object" && !(searchParams instanceof ValidatorDef) && !(searchParams instanceof Set) ? Object.keys(searchParams) : []
|
|
2774
|
+
);
|
|
2775
|
+
const checkConflicts = (sourceNames, targetNames, sourceLabel, targetLabel) => {
|
|
2776
|
+
const conflicts = [...sourceNames].filter((name) => targetNames.has(name));
|
|
2777
|
+
if (conflicts.length > 0) {
|
|
2778
|
+
throw new Error(
|
|
2779
|
+
`Query definition error: ${sourceLabel} [${conflicts.join(", ")}] conflict with ${targetLabel}. Please rename to avoid this conflict.`
|
|
2780
|
+
);
|
|
2781
|
+
}
|
|
2782
|
+
};
|
|
2783
|
+
checkConflicts(searchParamNames, pathParamNames, "Search param(s)", `path parameter(s) in "${path}"`);
|
|
2784
|
+
checkConflicts(bodyParamNames, pathParamNames, "Body field(s)", `path parameter(s) in "${path}"`);
|
|
2785
|
+
checkConflicts(bodyParamNames, searchParamNames, "Body field(s)", "search param(s)");
|
|
2761
2786
|
const fetchFn = async (context2, params) => {
|
|
2762
|
-
|
|
2787
|
+
let bodyData;
|
|
2788
|
+
let urlParams = params;
|
|
2789
|
+
if (hasBody) {
|
|
2790
|
+
bodyData = {};
|
|
2791
|
+
urlParams = params !== void 0 ? {} : void 0;
|
|
2792
|
+
if (params !== void 0) {
|
|
2793
|
+
for (const key in params) {
|
|
2794
|
+
if (bodyParamNames.has(key)) {
|
|
2795
|
+
bodyData[key] = params[key];
|
|
2796
|
+
} else {
|
|
2797
|
+
urlParams[key] = params[key];
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
const interpolatedPath = interpolatePath(urlParams ?? {});
|
|
2763
2803
|
const baseUrl = resolveBaseUrl(requestOptions?.baseUrl) ?? resolveBaseUrl(context2.baseUrl);
|
|
2764
2804
|
const fullUrl = baseUrl ? `${baseUrl}${interpolatedPath}` : interpolatedPath;
|
|
2765
|
-
const { baseUrl: _baseUrl, ...fetchOptions } = requestOptions ?? {};
|
|
2805
|
+
const { baseUrl: _baseUrl, headers: userHeaders, ...fetchOptions } = requestOptions ?? {};
|
|
2806
|
+
const headers = bodyData ? { "Content-Type": "application/json", ...userHeaders } : userHeaders;
|
|
2766
2807
|
const response2 = await context2.fetch(fullUrl, {
|
|
2767
2808
|
method,
|
|
2809
|
+
headers,
|
|
2810
|
+
body: bodyData ? JSON.stringify(bodyData) : void 0,
|
|
2768
2811
|
...fetchOptions
|
|
2769
2812
|
});
|
|
2770
2813
|
return response2.json();
|
|
@@ -2925,13 +2968,7 @@ function buildMutationFn(mutationDefinitionBuilder) {
|
|
|
2925
2968
|
const id = `mutation:${method}:${path}`;
|
|
2926
2969
|
const { shape: requestShape, shapeKey: requestShapeKey } = processTypeDef(request);
|
|
2927
2970
|
const { shape: responseShape, shapeKey: responseShapeKey } = processTypeDef(response);
|
|
2928
|
-
const interpolatePath = createPathInterpolator(path);
|
|
2929
|
-
const pathParamNames = /* @__PURE__ */ new Set();
|
|
2930
|
-
const paramRegex = /\[([^\]]+)\]/g;
|
|
2931
|
-
let match;
|
|
2932
|
-
while ((match = paramRegex.exec(path)) !== null) {
|
|
2933
|
-
pathParamNames.add(match[1]);
|
|
2934
|
-
}
|
|
2971
|
+
const { interpolate: interpolatePath, pathParamNames } = createPathInterpolator(path);
|
|
2935
2972
|
const mutateFn = async (context2, requestData) => {
|
|
2936
2973
|
const pathParams = {};
|
|
2937
2974
|
for (const paramName of pathParamNames) {
|