@nuasite/cms-sidecar 0.64.3 → 0.65.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/cli.bundle.js +28455 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +78 -28442
- package/dist/{types/concurrency.d.ts → concurrency.d.ts} +1 -1
- package/dist/concurrency.d.ts.map +1 -0
- package/dist/concurrency.js +75 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/media-from-env.d.ts.map +1 -0
- package/dist/media-from-env.js +57 -0
- package/dist/{types/portable.d.ts → portable.d.ts} +4 -4
- package/dist/portable.d.ts.map +1 -0
- package/dist/portable.js +11 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1100 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/package.json +11 -11
- package/src/cli.ts +2 -2
- package/src/concurrency.ts +5 -1
- package/src/index.ts +2 -2
- package/src/portable.ts +4 -4
- package/src/server.ts +2 -2
- package/src/tsconfig.json +5 -1
- package/dist/types/cli.d.ts.map +0 -1
- package/dist/types/concurrency.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/media-from-env.d.ts.map +0 -1
- package/dist/types/portable.d.ts.map +0 -1
- package/dist/types/server.d.ts.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/dist/types/types.d.ts.map +0 -1
- /package/dist/{types/cli.d.ts → cli.d.ts} +0 -0
- /package/dist/{types/media-from-env.d.ts → media-from-env.d.ts} +0 -0
- /package/dist/{types/server.d.ts → server.d.ts} +0 -0
- /package/dist/{types/types.d.ts → types.d.ts} +0 -0
|
@@ -20,9 +20,9 @@ export declare function hashSource(fs: CmsFileSystem, sourcePath: string): Promi
|
|
|
20
20
|
* predates a write which already completed.
|
|
21
21
|
*/
|
|
22
22
|
export declare class SharedRun<T> {
|
|
23
|
-
private readonly run;
|
|
24
23
|
private current;
|
|
25
24
|
private generation;
|
|
25
|
+
private readonly run;
|
|
26
26
|
constructor(run: () => Promise<T>);
|
|
27
27
|
get(): Promise<T>;
|
|
28
28
|
invalidate(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concurrency.d.ts","sourceRoot":"","sources":["../src/concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGtD;;;;;;;GAOG;AAEH,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAI9F;AAED;;;;GAIG;AACH,qBAAa,SAAS,CAAC,CAAC;IACvB,OAAO,CAAC,OAAO,CAA2D;IAC1E,OAAO,CAAC,UAAU,CAAI;IAEtB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;gBAE1B,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAIjC,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;IAWjB,UAAU,IAAI,IAAI;CAGlB;AAED;;;;GAIG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsC;IAEtD,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAetE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Hashing, per-file serialization and shared reads for the sidecar layer.
|
|
4
|
+
*
|
|
5
|
+
* cms-core stays hash-agnostic: the optimistic-concurrency `baseHash`/`sourceHash`
|
|
6
|
+
* comparison and the in-process mutex live here. Hashing reads the on-disk source
|
|
7
|
+
* through the same `CmsFileSystem` port cms-core uses, so the hash reflects exactly
|
|
8
|
+
* the bytes a subsequent `getEntry` would parse.
|
|
9
|
+
*/
|
|
10
|
+
/** Stable content hash of a UTF-8 string: `sha256:<hex>`. */
|
|
11
|
+
export function hashContent(content) {
|
|
12
|
+
return `sha256:${createHash('sha256').update(content, 'utf-8').digest('hex')}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hash the current on-disk source at `sourcePath`, or `null` when the file does
|
|
16
|
+
* not exist. Reads via the port so the hash matches the bytes cms-core sees.
|
|
17
|
+
*/
|
|
18
|
+
export async function hashSource(fs, sourcePath) {
|
|
19
|
+
if (!(await fs.exists(sourcePath)))
|
|
20
|
+
return null;
|
|
21
|
+
const raw = await fs.readFile(sourcePath);
|
|
22
|
+
return hashContent(raw);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One run of an expensive read at a time, shared by every caller that asks while it is in flight.
|
|
26
|
+
* `invalidate()` makes the next caller start a fresh run, so a caller never gets a result that
|
|
27
|
+
* predates a write which already completed.
|
|
28
|
+
*/
|
|
29
|
+
export class SharedRun {
|
|
30
|
+
current = null;
|
|
31
|
+
generation = 0;
|
|
32
|
+
run;
|
|
33
|
+
constructor(run) {
|
|
34
|
+
this.run = run;
|
|
35
|
+
}
|
|
36
|
+
get() {
|
|
37
|
+
if (this.current !== null && this.current.generation === this.generation)
|
|
38
|
+
return this.current.promise;
|
|
39
|
+
const entry = { generation: this.generation, promise: this.run() };
|
|
40
|
+
this.current = entry;
|
|
41
|
+
const release = () => {
|
|
42
|
+
if (this.current === entry)
|
|
43
|
+
this.current = null;
|
|
44
|
+
};
|
|
45
|
+
entry.promise.then(release, release);
|
|
46
|
+
return entry.promise;
|
|
47
|
+
}
|
|
48
|
+
invalidate() {
|
|
49
|
+
this.generation++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Serializes async work keyed by a string (a source path). Concurrent mutations
|
|
54
|
+
* of the same entry run one-after-another; different entries run in parallel.
|
|
55
|
+
* The chain self-cleans: a key's tail is dropped once its last waiter settles.
|
|
56
|
+
*/
|
|
57
|
+
export class KeyedMutex {
|
|
58
|
+
tails = new Map();
|
|
59
|
+
async runExclusive(key, task) {
|
|
60
|
+
const previous = this.tails.get(key) ?? Promise.resolve();
|
|
61
|
+
// Chain after the previous holder, swallowing its result/rejection so one
|
|
62
|
+
// failed mutation never poisons the next waiter on the same key.
|
|
63
|
+
const run = previous.then(() => task(), () => task());
|
|
64
|
+
this.tails.set(key, run);
|
|
65
|
+
try {
|
|
66
|
+
return await run;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
// Drop the entry only if no later waiter has chained onto it.
|
|
70
|
+
if (this.tails.get(key) === run) {
|
|
71
|
+
this.tails.delete(key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAClG,cAAc,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-from-env.d.ts","sourceRoot":"","sources":["../src/media-from-env.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,CAAA;AAQpE,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC7B;AAED,wBAAgB,YAAY,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,kBAAkB,CAuDrF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createContemberStorageAdapter, createLocalStorageAdapter, createS3StorageAdapter } from '@nuasite/cms-core';
|
|
2
|
+
const VALID_KINDS = ['contember', 's3', 'local', 'none'];
|
|
3
|
+
function isMediaAdapterKind(value) {
|
|
4
|
+
return VALID_KINDS.includes(value);
|
|
5
|
+
}
|
|
6
|
+
export function mediaFromEnv(env = process.env) {
|
|
7
|
+
const requested = env.CMS_MEDIA_ADAPTER?.trim().toLowerCase();
|
|
8
|
+
const kind = requested && isMediaAdapterKind(requested) ? requested : 'contember';
|
|
9
|
+
switch (kind) {
|
|
10
|
+
case 'none':
|
|
11
|
+
return { kind };
|
|
12
|
+
case 'local':
|
|
13
|
+
return {
|
|
14
|
+
kind,
|
|
15
|
+
adapter: createLocalStorageAdapter({
|
|
16
|
+
dir: env.CMS_MEDIA_LOCAL_DIR,
|
|
17
|
+
urlPrefix: env.CMS_MEDIA_LOCAL_URL_PREFIX,
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
case 's3': {
|
|
21
|
+
const bucket = env.CMS_MEDIA_S3_BUCKET;
|
|
22
|
+
const region = env.CMS_MEDIA_S3_REGION;
|
|
23
|
+
if (!bucket || !region) {
|
|
24
|
+
throw new Error('CMS_MEDIA_ADAPTER=s3 requires CMS_MEDIA_S3_BUCKET and CMS_MEDIA_S3_REGION');
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
kind,
|
|
28
|
+
adapter: createS3StorageAdapter({
|
|
29
|
+
bucket,
|
|
30
|
+
region,
|
|
31
|
+
accessKeyId: env.CMS_MEDIA_S3_ACCESS_KEY_ID,
|
|
32
|
+
secretAccessKey: env.CMS_MEDIA_S3_SECRET_ACCESS_KEY,
|
|
33
|
+
endpoint: env.CMS_MEDIA_S3_ENDPOINT,
|
|
34
|
+
cdnPrefix: env.CMS_MEDIA_S3_CDN_PREFIX,
|
|
35
|
+
prefix: env.CMS_MEDIA_S3_PREFIX,
|
|
36
|
+
}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
case 'contember': {
|
|
40
|
+
const apiBaseUrl = env.NUA_SITE_API_BASE_URL;
|
|
41
|
+
const projectSlug = env.NUA_SITE_PROJECT_SLUG;
|
|
42
|
+
// Without the API base + project slug we cannot reach the worker; treat as
|
|
43
|
+
// "no media configured" rather than constructing a broken adapter.
|
|
44
|
+
if (!apiBaseUrl || !projectSlug) {
|
|
45
|
+
return { kind: 'none' };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
kind,
|
|
49
|
+
adapter: createContemberStorageAdapter({
|
|
50
|
+
apiBaseUrl,
|
|
51
|
+
projectSlug,
|
|
52
|
+
sessionToken: env.NUA_SITE_SESSION_TOKEN,
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* adapter. The package root resolves here under the `workerd` condition.
|
|
4
4
|
*/
|
|
5
5
|
export { FIELD_TYPES, isFieldType } from '@nuasite/cms-types';
|
|
6
|
-
export { hashContent, hashSource, KeyedMutex } from './concurrency';
|
|
7
|
-
export { type CmsSidecarServer, createServer, type CreateServerOptions, SIDECAR_FEATURES } from './server';
|
|
8
|
-
export type { AddArrayItemBody, ApiError, Capabilities, ConflictResponse, CreateEntryBody, CreateFolderBody, EntriesListResult, EntriesQuery, ErrorCode, PageEntry, ProjectModel, RemoveArrayItemBody, RenameEntryBody, UpdateEntryBody, UpdateMediaAnnotationBody, } from './types';
|
|
9
|
-
export { STATUS_BY_CODE } from './types';
|
|
6
|
+
export { hashContent, hashSource, KeyedMutex } from './concurrency.ts';
|
|
7
|
+
export { type CmsSidecarServer, createServer, type CreateServerOptions, SIDECAR_FEATURES } from './server.ts';
|
|
8
|
+
export type { AddArrayItemBody, ApiError, Capabilities, ConflictResponse, CreateEntryBody, CreateFolderBody, EntriesListResult, EntriesQuery, ErrorCode, PageEntry, ProjectModel, RemoveArrayItemBody, RenameEntryBody, UpdateEntryBody, UpdateMediaAnnotationBody, } from './types.ts';
|
|
9
|
+
export { STATUS_BY_CODE } from './types.ts';
|
|
10
10
|
//# sourceMappingURL=portable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portable.d.ts","sourceRoot":"","sources":["../src/portable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAE,KAAK,gBAAgB,EAAE,YAAY,EAAE,KAAK,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC7G,YAAY,EACX,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,yBAAyB,GACzB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/portable.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sidecar without its environment-driven media setup, which constructs the Node-only local
|
|
3
|
+
* adapter. The package root resolves here under the `workerd` condition.
|
|
4
|
+
*/
|
|
5
|
+
// Re-export the wire contract's runtime field-type guard so consumers (the F2 BFF)
|
|
6
|
+
// can validate field types against the exact contract the sidecar serves — the
|
|
7
|
+
// same surfacing `@nuasite/cms` does. Keeps `@nuasite/cms-types` a real runtime dep.
|
|
8
|
+
export { FIELD_TYPES, isFieldType } from '@nuasite/cms-types';
|
|
9
|
+
export { hashContent, hashSource, KeyedMutex } from "./concurrency.js";
|
|
10
|
+
export { createServer, SIDECAR_FEATURES } from "./server.js";
|
|
11
|
+
export { STATUS_BY_CODE } from "./types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,OAAO,EACZ,KAAK,aAAa,EAclB,MAAM,mBAAmB,CAAA;AAmC1B,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAoB7C,CAAA;AAMD,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,OAAO,CAAA;IACb,kGAAkG;IAClG,EAAE,EAAE,aAAa,CAAA;IACjB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAA;IACZ,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAA;IACnB,kFAAkF;IAClF,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAA;CACtB;AAydD,MAAM,WAAW,gBAAgB;IAChC,6EAA6E;IAC7E,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CACtC;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,gBAAgB,CA2nBxE"}
|