@yolean/evidence-sdk 4.1.0 → 4.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @evidence-dev/sdk
2
2
 
3
+ ## 4.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 8b1f45215: Internal dependencies are published as ^ ranges instead of exact versions, so a release of one package no longer leaves its dependents pinned to the previous version.
8
+
9
+ ## 4.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 81977b64b: deployment.dataScope: pages with that route parameter load data/ and api/ from <basePath>/<value>/, and prerender their query results there.
14
+
3
15
  ## 4.1.0
4
16
 
5
17
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolean/evidence-sdk",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "evidence-sdk": "./src/cli.js"
@@ -89,7 +89,7 @@
89
89
  "@clack/prompts": "^0.7.0",
90
90
  "@evidence-dev/icons": "npm:@yolean/evidence-icons@^1.0.3",
91
91
  "@evidence-dev/telemetry": "npm:@yolean/evidence-telemetry@^2.1.4",
92
- "@evidence-dev/universal-sql": "npm:@yolean/evidence-universal-sql@3.0.2",
92
+ "@evidence-dev/universal-sql": "npm:@yolean/evidence-universal-sql@^3.1.0",
93
93
  "@steeze-ui/simple-icons": "^1.7.1",
94
94
  "@steeze-ui/tabler-icons": "^2.1.1",
95
95
  "@types/estree": "^1.0.5",
@@ -5,5 +5,14 @@ export const DeploymentConfigSchema = z.object({
5
5
  .string()
6
6
  .optional()
7
7
  .default('')
8
- .refine((value) => !value || value.startsWith('/'), { message: 'basePath must start with /' })
8
+ .refine((value) => !value || value.startsWith('/'), { message: 'basePath must start with /' }),
9
+ // A route parameter, e.g. orgslug: pages that have it load data/ and api/ from
10
+ // <basePath>/<value>/ and prerender their query results there, so each value's
11
+ // data can be served from its own prefix
12
+ dataScope: z
13
+ .string()
14
+ .optional()
15
+ .refine((value) => !value || /^[A-Za-z_][A-Za-z0-9_]*$/.test(value), {
16
+ message: 'dataScope must be a route parameter name'
17
+ })
9
18
  });
@@ -43,3 +43,32 @@ export const addBasePath = (path, config) => {
43
43
  return _path;
44
44
  }
45
45
  };
46
+
47
+ /**
48
+ * The data scope of a page: the value of the route parameter named by
49
+ * deployment.dataScope, or null when it isn't configured or the page lacks it
50
+ * @param {Record<string, string> | undefined} params
51
+ * @param {import("../../configuration/schemas/config.schema.js").EvidenceConfig} config
52
+ * @returns {string | null}
53
+ */
54
+ export const getDataScope = (params, config) => {
55
+ const param = config.deployment.dataScope;
56
+ if (!param || !params?.[param]) return null;
57
+ return params[param];
58
+ };
59
+
60
+ /**
61
+ * Like addBasePath, under /<scope> for pages with a data scope
62
+ * @param {string} path
63
+ * @param {string | null} scope
64
+ * @param {import("../../configuration/schemas/config.schema.js").EvidenceConfig} config
65
+ * @example addScopedBasePath('/data/manifest.json', 'org1', config) // '/base/org1/data/manifest.json'
66
+ * @returns {string}
67
+ */
68
+ export const addScopedBasePath = (path, scope, config) => {
69
+ if (!scope) return addBasePath(path, config);
70
+ return addBasePath(
71
+ `/${encodeURIComponent(scope)}${path.startsWith('/') ? '' : '/'}${path}`,
72
+ config
73
+ );
74
+ };
@@ -84,3 +84,25 @@ describe('addBasePath', () => {
84
84
  expect(addBasePath('test', config)).toBe('/base/test');
85
85
  });
86
86
  });
87
+
88
+ import { addScopedBasePath, getDataScope } from './addBasePath.js';
89
+ describe('data scope', () => {
90
+ const scoped = { deployment: { basePath: '/base', dataScope: 'orgslug' } };
91
+ it('is the value of the configured route parameter', () => {
92
+ expect(getDataScope({ orgslug: 'org1' }, scoped)).toBe('org1');
93
+ });
94
+ it('is null for pages without the parameter, or without dataScope', () => {
95
+ expect(getDataScope({ site: 's' }, scoped)).toBe(null);
96
+ expect(getDataScope(undefined, scoped)).toBe(null);
97
+ expect(getDataScope({ orgslug: 'org1' }, { deployment: { basePath: '/base' } })).toBe(null);
98
+ });
99
+ it('puts scoped paths under /<scope> after the base path', () => {
100
+ expect(addScopedBasePath('/data/manifest.json', 'org1', scoped)).toBe(
101
+ '/base/org1/data/manifest.json'
102
+ );
103
+ expect(addScopedBasePath('api/x.json', 'org1', scoped)).toBe('/base/org1/api/x.json');
104
+ });
105
+ it('leaves unscoped paths to addBasePath', () => {
106
+ expect(addScopedBasePath('/data/manifest.json', null, scoped)).toBe('/base/data/manifest.json');
107
+ });
108
+ });
@@ -1,5 +1,13 @@
1
1
  export * from './inputs.js';
2
- import { addBasePath as _addBasePath } from './addBasePath.js';
2
+ import {
3
+ addBasePath as _addBasePath,
4
+ addScopedBasePath as _addScopedBasePath,
5
+ getDataScope as _getDataScope
6
+ } from './addBasePath.js';
3
7
  import { config } from '$evidence/config';
4
8
  /** @type {(path: string) => string} */
5
9
  export const addBasePath = (path) => _addBasePath(path, config);
10
+ /** @type {(params: Record<string, string> | undefined) => string | null} */
11
+ export const getDataScope = (params) => _getDataScope(params, config);
12
+ /** @type {(path: string, scope: string | null) => string} */
13
+ export const addScopedBasePath = (path, scope) => _addScopedBasePath(path, scope, config);