@projectdochelp/s3te 1.0.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.
@@ -0,0 +1,136 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ import { applyContentQuery, getContentTypeForPath } from "../../core/src/index.mjs";
5
+
6
+ function normalizeKey(key) {
7
+ return String(key).replace(/\\/g, "/");
8
+ }
9
+
10
+ export class InMemoryTemplateRepository {
11
+ constructor(files = {}) {
12
+ this.files = new Map(Object.entries(files).map(([key, value]) => [
13
+ normalizeKey(key),
14
+ {
15
+ key: normalizeKey(key),
16
+ body: value,
17
+ contentType: getContentTypeForPath(key)
18
+ }
19
+ ]));
20
+ }
21
+
22
+ async get(key) {
23
+ return this.files.get(normalizeKey(key)) ?? null;
24
+ }
25
+
26
+ async listVariantEntries(variant) {
27
+ const prefix = `${variant}/`;
28
+ return [...this.files.values()].filter((entry) => entry.key.startsWith(prefix));
29
+ }
30
+
31
+ async exists(key) {
32
+ return this.files.has(normalizeKey(key));
33
+ }
34
+ }
35
+
36
+ export class InMemoryContentRepository {
37
+ constructor(items = []) {
38
+ this.items = [...items];
39
+ }
40
+
41
+ async getByContentId(contentId) {
42
+ return this.items.find((item) => item.contentId === contentId) ?? null;
43
+ }
44
+
45
+ async query(query) {
46
+ return applyContentQuery(this.items, query);
47
+ }
48
+ }
49
+
50
+ export class MemoryDependencyStore {
51
+ constructor() {
52
+ this.bySource = new Map();
53
+ }
54
+
55
+ async replaceSourceDependencies(record) {
56
+ this.bySource.set(record.sourceId, record);
57
+ }
58
+
59
+ async findDependentsByDependency(ref) {
60
+ const dependencyKey = `${ref.kind}#${ref.id}`;
61
+ return [...this.bySource.values()].filter((record) => record.dependencies.some((dependency) => (
62
+ `${dependency.kind}#${dependency.id}` === dependencyKey
63
+ )));
64
+ }
65
+
66
+ async findGeneratedOutputsByTemplate(templateKey, scope) {
67
+ return [...this.bySource.values()]
68
+ .filter((record) => record.templateKey === templateKey
69
+ && record.environment === scope.environment
70
+ && record.variant === scope.variant
71
+ && record.language === scope.language)
72
+ .map((record) => ({
73
+ environment: record.environment,
74
+ variant: record.variant,
75
+ language: record.language,
76
+ templateKey: record.templateKey,
77
+ outputKey: record.outputKey
78
+ }));
79
+ }
80
+
81
+ async deleteOutput(output) {
82
+ const sourceId = `${output.environment}#${output.variant}#${output.language}#${output.outputKey}`;
83
+ this.bySource.delete(sourceId);
84
+ }
85
+ }
86
+
87
+ export class CollectingOutputPublisher {
88
+ constructor() {
89
+ this.operations = [];
90
+ }
91
+
92
+ async put(artifact, target) {
93
+ this.operations.push({ type: "put", artifact, target });
94
+ }
95
+
96
+ async copySourceObject(sourceKey, target) {
97
+ this.operations.push({ type: "copy", sourceKey, target });
98
+ }
99
+
100
+ async delete(outputKey, target) {
101
+ this.operations.push({ type: "delete", outputKey, target });
102
+ }
103
+ }
104
+
105
+ export class CollectingInvalidationScheduler {
106
+ constructor() {
107
+ this.requests = [];
108
+ }
109
+
110
+ async enqueue(request) {
111
+ this.requests.push(request);
112
+ }
113
+ }
114
+
115
+ export async function loadContentFixtures(projectDir, languageCode) {
116
+ const candidates = [
117
+ path.join(projectDir, "offline", "content", `${languageCode}.json`),
118
+ path.join(projectDir, "offline", "content", "items.json"),
119
+ path.join(projectDir, "content", `${languageCode}.json`),
120
+ path.join(projectDir, "content", "items.json")
121
+ ];
122
+
123
+ for (const candidate of candidates) {
124
+ try {
125
+ const raw = await fs.readFile(candidate, "utf8");
126
+ const items = JSON.parse(raw);
127
+ if (Array.isArray(items)) {
128
+ return items;
129
+ }
130
+ } catch {
131
+ // optional fixture file
132
+ }
133
+ }
134
+
135
+ return [];
136
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export * from "../packages/core/src/index.mjs";
2
+ export * from "../packages/testkit/src/index.mjs";
3
+ export * from "../packages/aws-adapter/src/index.mjs";