@paroicms/public-server-lib 0.45.2 → 0.46.1
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/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/load-descriptors.d.ts +19 -0
- package/dist/load-descriptors.js +42 -0
- package/dist/load-descriptors.js.map +1 -0
- package/dist/site-schema-public-helpers.d.ts +3 -0
- package/dist/site-schema-public-helpers.js +15 -0
- package/dist/site-schema-public-helpers.js.map +1 -0
- package/package.json +6 -6
- package/types/backend-plugin-types.d.ts +31 -38
- package/types/load-descriptor-types.d.ts +43 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,12 @@ export type * from "../typeonly/configuration-types.d.ts";
|
|
|
3
3
|
export type * from "../typeonly/site-schema-json-types.d.ts";
|
|
4
4
|
export type * from "../typeonly/theme-json-types.d.ts";
|
|
5
5
|
export type * from "../types/backend-plugin-types.d.ts";
|
|
6
|
+
export type * from "../types/load-descriptor-types.d.ts";
|
|
6
7
|
export * from "./api-error-handler.js";
|
|
7
8
|
export * from "./html-helpers.js";
|
|
9
|
+
export * from "./load-descriptors.js";
|
|
8
10
|
export * from "./obfuscate.helper.js";
|
|
9
11
|
export * from "./server-image-cache-engine.helper.js";
|
|
10
12
|
export * from "./simple-i18n.js";
|
|
13
|
+
export * from "./site-schema-public-helpers.js";
|
|
11
14
|
export * from "./typeonly-validator.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export * from "./api-error-handler.js";
|
|
2
2
|
export * from "./html-helpers.js";
|
|
3
|
+
export * from "./load-descriptors.js";
|
|
3
4
|
export * from "./obfuscate.helper.js";
|
|
4
5
|
export * from "./server-image-cache-engine.helper.js";
|
|
5
6
|
export * from "./simple-i18n.js";
|
|
7
|
+
export * from "./site-schema-public-helpers.js";
|
|
6
8
|
export * from "./typeonly-validator.js";
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC;AACtD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DocumentsLoadDescriptor, ListBaseDescriptor, LoadDescriptor, OneDocumentLoadDescriptor } from "../types/load-descriptor-types.js";
|
|
2
|
+
declare const loadDescriptorSymbol: unique symbol;
|
|
3
|
+
export interface WithLoadDescriptor<T extends LoadDescriptor = LoadDescriptor> {
|
|
4
|
+
[loadDescriptorSymbol]: T;
|
|
5
|
+
}
|
|
6
|
+
export interface WithOneDocumentLoadDescriptor {
|
|
7
|
+
[loadDescriptorSymbol]: OneDocumentLoadDescriptor;
|
|
8
|
+
}
|
|
9
|
+
export interface WithDocumentsLoadDescriptor {
|
|
10
|
+
[loadDescriptorSymbol]: DocumentsLoadDescriptor;
|
|
11
|
+
}
|
|
12
|
+
export declare function assignLoadDescriptor<T>(val: T, loadDescriptor: OneDocumentLoadDescriptor): T & WithOneDocumentLoadDescriptor;
|
|
13
|
+
export declare function assignLoadDescriptor<T>(val: T, loadDescriptor: DocumentsLoadDescriptor): T & WithDocumentsLoadDescriptor;
|
|
14
|
+
export declare function assignLoadDescriptor<T>(val: T, loadDescriptor: LoadDescriptor): T & WithLoadDescriptor;
|
|
15
|
+
export declare function extractLoadDescriptor(val: unknown): LoadDescriptor | undefined;
|
|
16
|
+
export declare function extractOneDocumentLoadDescriptor(val: unknown): OneDocumentLoadDescriptor | undefined;
|
|
17
|
+
export declare function extractDocumentsLoadDescriptor(val: unknown): DocumentsLoadDescriptor | undefined;
|
|
18
|
+
export declare function mergeListDescriptor<T extends ListBaseDescriptor>(base: T, newValues: ListBaseDescriptor): T;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const loadDescriptorSymbol = Symbol("loadDescriptor");
|
|
2
|
+
export function assignLoadDescriptor(val, loadDescriptor) {
|
|
3
|
+
val[loadDescriptorSymbol] = loadDescriptor;
|
|
4
|
+
return val;
|
|
5
|
+
}
|
|
6
|
+
export function extractLoadDescriptor(val) {
|
|
7
|
+
if (typeof val !== "object" || val === null)
|
|
8
|
+
return;
|
|
9
|
+
if (!(loadDescriptorSymbol in val))
|
|
10
|
+
return;
|
|
11
|
+
const payload = val[loadDescriptorSymbol];
|
|
12
|
+
return payload;
|
|
13
|
+
}
|
|
14
|
+
export function extractOneDocumentLoadDescriptor(val) {
|
|
15
|
+
const payload = extractLoadDescriptor(val);
|
|
16
|
+
if (!payload)
|
|
17
|
+
return;
|
|
18
|
+
return payload.load === "one" && payload.nodeKind === "document" ? payload : undefined;
|
|
19
|
+
}
|
|
20
|
+
export function extractDocumentsLoadDescriptor(val) {
|
|
21
|
+
const payload = extractLoadDescriptor(val);
|
|
22
|
+
if (!payload)
|
|
23
|
+
return;
|
|
24
|
+
return payload.load === "list" && payload.nodeKind === "document" ? payload : undefined;
|
|
25
|
+
}
|
|
26
|
+
export function mergeListDescriptor(base, newValues) {
|
|
27
|
+
const target = { ...base };
|
|
28
|
+
if (newValues.labeledWith) {
|
|
29
|
+
target.labeledWith = newValues.labeledWith;
|
|
30
|
+
}
|
|
31
|
+
if (newValues.sorting) {
|
|
32
|
+
target.sorting = newValues.sorting;
|
|
33
|
+
}
|
|
34
|
+
if (newValues.offset !== undefined) {
|
|
35
|
+
target.offset = newValues.offset;
|
|
36
|
+
}
|
|
37
|
+
if (newValues.limit !== undefined) {
|
|
38
|
+
target.limit = newValues.limit;
|
|
39
|
+
}
|
|
40
|
+
return target;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=load-descriptors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-descriptors.js","sourceRoot":"","sources":["../src/load-descriptors.ts"],"names":[],"mappings":"AAOA,MAAM,oBAAoB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AA0BtD,MAAM,UAAU,oBAAoB,CAAC,GAAQ,EAAE,cAA8B;IAC3E,GAAG,CAAC,oBAAoB,CAAC,GAAG,cAAc,CAAC;IAC3C,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,GAAY;IAChD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO;IACpD,IAAI,CAAC,CAAC,oBAAoB,IAAI,GAAG,CAAC;QAAE,OAAO;IAC3C,MAAM,OAAO,GAAG,GAAG,CAAC,oBAAoB,CAAmB,CAAC;IAC5D,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,GAAY;IAEZ,MAAM,OAAO,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,OAAO,CAAC,IAAI,KAAK,KAAK,IAAI,OAAO,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACzF,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,GAAY;IACzD,MAAM,OAAO,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,OAAO,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,IAAO,EACP,SAA6B;IAE7B,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IAC3B,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QAC1B,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC;IAC7C,CAAC;IACD,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;IACrC,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IACnC,CAAC;IACD,IAAI,SAAS,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAClC,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function parseSorting(val) {
|
|
2
|
+
if (val === "manual")
|
|
3
|
+
return "manual";
|
|
4
|
+
const regularChildrenSorting = [];
|
|
5
|
+
const arr = typeof val === "string" ? val.split(/\s*,\s*/) : val;
|
|
6
|
+
for (const item of arr) {
|
|
7
|
+
const [fieldName, direction] = item.split(/\s+/);
|
|
8
|
+
if ((direction !== "asc" && direction !== "desc") || !/^[a-zA-Z]+$/.test(fieldName)) {
|
|
9
|
+
throw new Error(`invalid child ordering '${item}'`);
|
|
10
|
+
}
|
|
11
|
+
regularChildrenSorting.push({ fieldName, direction });
|
|
12
|
+
}
|
|
13
|
+
return regularChildrenSorting;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=site-schema-public-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-schema-public-helpers.js","sourceRoot":"","sources":["../src/site-schema-public-helpers.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,YAAY,CAAC,GAAc;IACzC,IAAI,GAAG,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAEtC,MAAM,sBAAsB,GAAiB,EAAE,CAAC;IAChD,MAAM,GAAG,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACjE,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;QACvB,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,SAAS,KAAK,KAAK,IAAI,SAAS,KAAK,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACpF,MAAM,IAAI,KAAK,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC;QACtD,CAAC;QACD,sBAAsB,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paroicms/public-server-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"description": "Common utilitaries for paroicms plugins (backend side).",
|
|
5
5
|
"author": "Paroi Team",
|
|
6
6
|
"repository": {
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "npm run typeonly && npm run tsc",
|
|
17
17
|
"tsc": "tsc",
|
|
18
|
-
"typeonly": "typeonly --bundle dist/types.to.json -
|
|
18
|
+
"typeonly": "typeonly --bundle dist/types.to.json --source-dir typeonly",
|
|
19
19
|
"test:watch": "vitest",
|
|
20
20
|
"test": "vitest run",
|
|
21
21
|
"clear": "rimraf dist/*",
|
|
22
22
|
"dev": "tsc --watch --preserveWatchOutput"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@paroicms/internal-anywhere-lib": "1.
|
|
26
|
-
"@paroicms/public-anywhere-lib": "0.
|
|
27
|
-
"@paroicms/script-lib": "0.
|
|
25
|
+
"@paroicms/internal-anywhere-lib": "1.35.1",
|
|
26
|
+
"@paroicms/public-anywhere-lib": "0.36.1",
|
|
27
|
+
"@paroicms/script-lib": "0.3.1",
|
|
28
28
|
"@typeonly/validator": "~1.1.2",
|
|
29
29
|
"arktype": "~2.1.20"
|
|
30
30
|
},
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@types/node": "~24.0.1",
|
|
33
33
|
"rimraf": "~6.0.1",
|
|
34
34
|
"typeonly": "~1.1.3",
|
|
35
|
-
"typescript": "~5.
|
|
35
|
+
"typescript": "~5.9.2",
|
|
36
36
|
"vitest": "~3.2.3"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
WithAttachedData,
|
|
18
18
|
} from "@paroicms/public-anywhere-lib";
|
|
19
19
|
import type Stream from "node:stream";
|
|
20
|
+
import type { DocumentsLoadDescriptor } from "./load-descriptor-types.d.ts";
|
|
20
21
|
|
|
21
22
|
export interface PaHttpContext {
|
|
22
23
|
req: PaHttpRequest;
|
|
@@ -88,15 +89,11 @@ export interface BackendPluginInitService extends PluginStaticConfiguration {
|
|
|
88
89
|
handler: PluginLiquidFilterHandler,
|
|
89
90
|
options?: { raw?: boolean },
|
|
90
91
|
): void;
|
|
91
|
-
|
|
92
|
+
registerSetLiquidTagFunction(tagName: string, handler: PluginSetLiquidTagHandler): void;
|
|
93
|
+
registerOutLiquidTagFunction(
|
|
92
94
|
tagName: string,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
): void;
|
|
96
|
-
registerLiquidTag(
|
|
97
|
-
tagName: string,
|
|
98
|
-
tagKind: "injectHtml",
|
|
99
|
-
handler: PluginLiquidTagReturnsHtmlHandler,
|
|
95
|
+
handler: PluginOutLiquidTagHandler,
|
|
96
|
+
options?: { raw?: boolean },
|
|
100
97
|
): void;
|
|
101
98
|
registerHook(
|
|
102
99
|
hookName: "initialized",
|
|
@@ -160,18 +157,21 @@ export type PluginLiquidFilterHandler = (
|
|
|
160
157
|
},
|
|
161
158
|
) => string | undefined | Promise<string | undefined>;
|
|
162
159
|
|
|
163
|
-
export type
|
|
160
|
+
export type PluginSetLiquidTagHandler = (
|
|
164
161
|
service: PluginRenderingService,
|
|
165
162
|
options: {
|
|
166
|
-
|
|
163
|
+
positionedParameters: unknown[];
|
|
167
164
|
namedParameters: { [key: string]: unknown };
|
|
168
165
|
variableName: string;
|
|
169
166
|
},
|
|
170
|
-
) => Generator
|
|
167
|
+
) => Generator<unknown, unknown, unknown>;
|
|
171
168
|
|
|
172
|
-
export type
|
|
169
|
+
export type PluginOutLiquidTagHandler = (
|
|
173
170
|
service: PluginRenderingService,
|
|
174
|
-
|
|
171
|
+
options: {
|
|
172
|
+
positionedParameters: unknown[];
|
|
173
|
+
namedParameters: { [key: string]: unknown };
|
|
174
|
+
},
|
|
175
175
|
) => string | Promise<string>;
|
|
176
176
|
|
|
177
177
|
export type PublicApiHandler = (
|
|
@@ -238,22 +238,20 @@ export interface PluginRenderingService {
|
|
|
238
238
|
language: string;
|
|
239
239
|
homeUrl: string;
|
|
240
240
|
setRenderState(key: string, value: any): void;
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
): Promise<
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
start: number;
|
|
256
|
-
templateName: string;
|
|
241
|
+
|
|
242
|
+
loadDocuments(loadDescriptor: DocumentsLoadDescriptor): Promise<TpDocument[]>;
|
|
243
|
+
loadDocuments(
|
|
244
|
+
loadDescriptor: DocumentsLoadDescriptor,
|
|
245
|
+
options: { withTotal: true },
|
|
246
|
+
): Promise<{ documents: TpDocument[]; total: number }>;
|
|
247
|
+
|
|
248
|
+
renderDocument(templateName: string, doc: TpDocument): Promise<string>;
|
|
249
|
+
|
|
250
|
+
serve(
|
|
251
|
+
httpContext: PaHttpContext,
|
|
252
|
+
response: {
|
|
253
|
+
content: string;
|
|
254
|
+
contentType: string;
|
|
257
255
|
},
|
|
258
256
|
): Promise<void>;
|
|
259
257
|
|
|
@@ -272,9 +270,10 @@ export interface PluginRenderingService {
|
|
|
272
270
|
close(): Promise<void>;
|
|
273
271
|
}
|
|
274
272
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
273
|
+
/** This type is a stub for `TpDocPayload`. It represents a full `doc` payload for LiquidJS templates. */
|
|
274
|
+
export interface TpDocument {
|
|
275
|
+
kind: "routingDocument" | "regularDocument";
|
|
276
|
+
id: string;
|
|
278
277
|
}
|
|
279
278
|
|
|
280
279
|
export interface PublicDocument {
|
|
@@ -324,12 +323,6 @@ export interface AppLogger {
|
|
|
324
323
|
debug(...messages: any[]): void;
|
|
325
324
|
}
|
|
326
325
|
|
|
327
|
-
export interface PartialsParamsInput {
|
|
328
|
-
templateName: string;
|
|
329
|
-
offset: number;
|
|
330
|
-
limit: number;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
326
|
export interface RegisteredSite {
|
|
334
327
|
readonly fqdn: string;
|
|
335
328
|
readonly siteName: string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ParsedLNodeId, ScSorting } from "@paroicms/public-anywhere-lib";
|
|
2
|
+
|
|
3
|
+
export type LoadDescriptor = DocumentsLoadDescriptor | OneDocumentLoadDescriptor;
|
|
4
|
+
|
|
5
|
+
export type DocumentsLoadDescriptor = ChildDocumentsLoadDescriptor | SearchDocumentsLoadDescriptor;
|
|
6
|
+
|
|
7
|
+
export interface ListBaseDescriptor {
|
|
8
|
+
offset?: number;
|
|
9
|
+
limit?: number;
|
|
10
|
+
sorting?: ScSorting;
|
|
11
|
+
labeledWith?: LabeledWithDescriptor;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface LabeledWithDescriptor {
|
|
15
|
+
fieldName: string;
|
|
16
|
+
termNodeId: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ChildDocumentsLoadDescriptor extends ListBaseDescriptor {
|
|
20
|
+
load: "list";
|
|
21
|
+
nodeKind: "document";
|
|
22
|
+
descriptorName: "children";
|
|
23
|
+
parentDocumentId: ParsedLNodeId;
|
|
24
|
+
/**
|
|
25
|
+
* If omitted, an additional query to fetch the type name will be made to the database.
|
|
26
|
+
*/
|
|
27
|
+
parentDocumentTypeName?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SearchDocumentsLoadDescriptor extends ListBaseDescriptor {
|
|
31
|
+
load: "list";
|
|
32
|
+
nodeKind: "document";
|
|
33
|
+
descriptorName: "search";
|
|
34
|
+
language: string;
|
|
35
|
+
words: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface OneDocumentLoadDescriptor {
|
|
39
|
+
load: "one";
|
|
40
|
+
nodeKind: "document";
|
|
41
|
+
descriptorName: "id";
|
|
42
|
+
documentId: ParsedLNodeId;
|
|
43
|
+
}
|