@arkstack/view 0.7.20 → 0.9.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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference path="./app.d.ts" />
2
+ import { t as clearRouterViewPlugin } from "./plugins-D3vyoc8i.js";
2
3
  import edge, { Edge, Edge as Edge$1 } from "edge.js";
3
4
 
4
5
  //#region src/ViewInstance.d.ts
@@ -25,6 +26,10 @@ declare class ViewInstance implements PromiseLike<string> {
25
26
  }
26
27
  //#endregion
27
28
  //#region src/types.d.ts
29
+ type ViewErrorValue = string | string[] | Error | {
30
+ message?: unknown;
31
+ } | unknown;
32
+ type ViewErrorRecord = Record<string, ViewErrorValue>;
28
33
  type ComposerRunner = (view: ViewInstance) => Promise<void>;
29
34
  type SyncComposerRunner = (view: ViewInstance) => void;
30
35
  type ViewData = Record<string, any>;
@@ -53,7 +58,7 @@ declare class ViewFactory {
53
58
  constructor(options?: ViewFactoryOptions);
54
59
  make(name: ViewName, data?: ViewData): ViewInstance;
55
60
  first(names: ViewName[], data?: ViewData): ViewInstance;
56
- exists(name: ViewName): any;
61
+ exists(name: ViewName): boolean;
57
62
  share(key: string, value: any): this;
58
63
  share(data: ViewData): this;
59
64
  composer(names: ViewComposerName, composer: ViewComposer): this;
@@ -76,7 +81,7 @@ declare class View {
76
81
  static factoryInstance(): ViewFactory;
77
82
  static make(name: ViewName, data?: ViewData): ViewInstance;
78
83
  static first(names: ViewName[], data?: ViewData): ViewInstance;
79
- static exists(name: ViewName): any;
84
+ static exists(name: ViewName): boolean;
80
85
  static share(key: string, value: any): typeof View;
81
86
  static share(data: ViewData): typeof View;
82
87
  static composer(names: ViewComposerName, composer: ViewComposer): typeof View;
@@ -85,6 +90,34 @@ declare class View {
85
90
  static raw(name: ViewName, contents: string): typeof View;
86
91
  }
87
92
  //#endregion
93
+ //#region src/ViewErrorBag.d.ts
94
+ declare class ViewErrorBag {
95
+ private bag;
96
+ constructor(errors?: ViewErrorRecord | ViewErrorBag | unknown);
97
+ add(field: string, message: ViewErrorValue): this;
98
+ merge(errors: ViewErrorRecord | ViewErrorBag | unknown): this;
99
+ keys(): string[];
100
+ get(field?: string): string[];
101
+ first(field?: string | null): string;
102
+ has(field?: string | string[] | null): boolean;
103
+ hasAny(fields: string | string[]): boolean;
104
+ missing(fields: string | string[]): boolean;
105
+ any(): boolean;
106
+ isEmpty(): boolean;
107
+ isNotEmpty(): boolean;
108
+ count(): number;
109
+ all(): string[];
110
+ unique(): string[];
111
+ clear(field?: string | string[]): this;
112
+ forget(field: string): this;
113
+ messagesRaw(): Record<string, string[]>;
114
+ getMessages(): Record<string, string[]>;
115
+ getMessageBag(): this;
116
+ toArray(): Record<string, string[]>;
117
+ toJSON(): Record<string, string[]>;
118
+ }
119
+ declare const normalizeViewErrors: (errors?: unknown) => Pick<ViewErrorBag, "all" | "first" | "get" | "has">;
120
+ //#endregion
88
121
  //#region src/helpers.d.ts
89
122
  declare function view(): ViewFactory;
90
123
  declare function view(name: ViewName, data?: ViewData): ViewInstance;
@@ -99,7 +132,14 @@ type PackageViewReference = {
99
132
  edgeName: string;
100
133
  };
101
134
  declare const parsePackageViewName: (name: string) => PackageViewReference | null;
102
- declare const resolvePackageViewsPath: (nodePackageName: string, viewPath?: string) => any;
135
+ declare const resolvePackageViewsPath: (nodePackageName: string, viewPath?: string) => string;
136
+ //#endregion
137
+ //#region src/viewContext.d.ts
138
+ declare const getViewData: () => ViewData;
139
+ declare const enterViewData: (data?: ViewData) => void;
140
+ declare const runWithViewData: <T>(data: ViewData, callback: () => T | Promise<T>) => Promise<T>;
141
+ declare const clearViewData: () => void;
142
+ declare const collectViewData: (context: Record<string, any>) => ViewData;
103
143
  //#endregion
104
- export { ComposerRunner, Edge, SyncComposerRunner, View, ViewComposer, ViewComposerClass, ViewComposerHandler, ViewComposerName, ViewComposerObject, ViewData, ViewFactory, ViewFactoryOptions, ViewInstance, ViewName, edge, parsePackageViewName, resolvePackageViewsPath, view };
144
+ export { ComposerRunner, Edge, SyncComposerRunner, View, ViewComposer, ViewComposerClass, ViewComposerHandler, ViewComposerName, ViewComposerObject, ViewData, ViewErrorBag, ViewErrorRecord, ViewErrorValue, ViewFactory, ViewFactoryOptions, ViewInstance, ViewName, clearRouterViewPlugin, clearViewData, collectViewData, edge, enterViewData, getViewData, normalizeViewErrors, parsePackageViewName, resolvePackageViewsPath, runWithViewData, view };
105
145
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,247 +1,3 @@
1
- import { existsSync } from "node:fs";
2
- import { resolve } from "node:path";
3
- import edge, { Edge, Edge as Edge$1 } from "edge.js";
4
- //#region src/helpers.ts
5
- function view(name, data = {}) {
6
- if (name === void 0) return View.factoryInstance();
7
- return View.make(name, data);
8
- }
9
- const isClass = (target) => {
10
- return typeof target === "function" && /^class\s/.test(Function.prototype.toString.call(target));
11
- };
12
- const mergeData = (target, data) => {
13
- if (data.length === 0) return target;
14
- if (typeof data[0] === "string") {
15
- target[data[0]] = data[1];
16
- return target;
17
- }
18
- for (const value of data) if (value && typeof value === "object" && !Array.isArray(value)) Object.assign(target, value);
19
- return target;
20
- };
21
- const runComposerSync = (composer, view) => {
22
- const result = runComposer(composer, view);
23
- if (result && typeof result.then === "function") throw new Error("Async view composers cannot be used with renderSync.");
24
- };
25
- const runComposer = (composer, view) => {
26
- if (typeof composer === "function") {
27
- if (isClass(composer)) return new composer().compose(view);
28
- return composer(view);
29
- }
30
- return composer.compose(view);
31
- };
32
- //#endregion
33
- //#region src/packageViews.ts
34
- const parsePackageViewName = (name) => {
35
- if (!name.startsWith("~")) return null;
36
- const source = name.slice(1);
37
- const slashIndex = source.indexOf("/");
38
- const dotIndex = slashIndex === -1 ? source.indexOf(".") : source.indexOf(".", slashIndex);
39
- if (dotIndex <= 0) throw new Error(`Invalid package view name: ${name}`);
40
- const packageName = source.slice(0, dotIndex);
41
- const viewName = source.slice(dotIndex + 1);
42
- if (!viewName) throw new Error(`Invalid package view name: ${name}`);
43
- const nodePackageName = slashIndex === -1 ? packageName : `@${packageName}`;
44
- const diskName = `package_${packageName.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
45
- return {
46
- source: name,
47
- packageName,
48
- nodePackageName,
49
- diskName,
50
- viewName,
51
- edgeName: `${diskName}::${viewName}`
52
- };
53
- };
54
- const resolvePackageViewsPath = (nodePackageName, viewPath = "resources/views") => {
55
- const viewsPath = resolve(resolve(process.cwd(), "node_modules", nodePackageName), viewPath);
56
- if (!existsSync(viewsPath)) throw new Error(`Package views directory not found: ${viewsPath}`);
57
- return viewsPath;
58
- };
59
- //#endregion
60
- //#region src/ViewInstance.ts
61
- var ViewInstance = class {
62
- name;
63
- renderer;
64
- runComposers;
65
- runComposersSync;
66
- renderName;
67
- payload;
68
- composersHaveRun = false;
69
- constructor(name, data = {}, renderer, runComposers, runComposersSync, renderName = name) {
70
- this.name = name;
71
- this.renderer = renderer;
72
- this.runComposers = runComposers;
73
- this.runComposersSync = runComposersSync;
74
- this.renderName = renderName;
75
- this.payload = { ...data };
76
- }
77
- get data() {
78
- return this.payload;
79
- }
80
- with(...data) {
81
- mergeData(this.payload, data);
82
- return this;
83
- }
84
- async render() {
85
- await this.compose();
86
- return await this.renderer.render(this.renderName, this.payload);
87
- }
88
- renderSync() {
89
- this.composeSync();
90
- return this.renderer.renderSync(this.renderName, this.payload);
91
- }
92
- then(onfulfilled, onrejected) {
93
- return this.render().then(onfulfilled, onrejected);
94
- }
95
- async compose() {
96
- if (this.composersHaveRun) return;
97
- this.composersHaveRun = true;
98
- await this.runComposers(this);
99
- }
100
- composeSync() {
101
- if (this.composersHaveRun) return;
102
- this.composersHaveRun = true;
103
- this.runComposersSync(this);
104
- }
105
- };
106
- //#endregion
107
- //#region src/ViewFactory.ts
108
- var ViewFactory = class {
109
- edge;
110
- sharedData = {};
111
- composers = /* @__PURE__ */ new Map();
112
- mountedPackages = /* @__PURE__ */ new Set();
113
- packageViewsPath;
114
- constructor(options = {}) {
115
- this.edge = options.edge ?? Edge$1.create({ cache: options.cache });
116
- this.packageViewsPath = options.packageViewsPath ?? "resources/views";
117
- this.mount(options.viewsPath ?? resolve(process.cwd(), "src", "resources", "views"));
118
- }
119
- make(name, data = {}) {
120
- const edgeName = this.resolveName(name);
121
- return new ViewInstance(name, {
122
- ...this.sharedData,
123
- ...data
124
- }, this.edge, async (view) => await this.runComposers(name, view), (view) => this.runComposersSync(name, view), edgeName);
125
- }
126
- first(names, data = {}) {
127
- const name = names.find((candidate) => this.exists(candidate));
128
- if (!name) throw new Error(`None of the given views exist: ${names.join(", ")}`);
129
- return this.make(name, data);
130
- }
131
- exists(name) {
132
- const edgeName = this.resolveName(name);
133
- if (this.edge.loader.templates[edgeName]) return true;
134
- try {
135
- return existsSync(this.edge.loader.makePath(edgeName));
136
- } catch {
137
- return false;
138
- }
139
- }
140
- share(...data) {
141
- mergeData(this.sharedData, data);
142
- return this;
143
- }
144
- composer(names, composer) {
145
- for (const name of Array.isArray(names) ? names : [names]) this.composers.set(name, [...this.composers.get(name) ?? [], composer]);
146
- return this;
147
- }
148
- mount(diskName, viewsDirectory) {
149
- if (viewsDirectory === void 0) {
150
- this.edge.mount(diskName);
151
- return this;
152
- }
153
- this.edge.mount(diskName, viewsDirectory);
154
- return this;
155
- }
156
- raw(name, contents) {
157
- this.edge.registerTemplate(name, { template: contents });
158
- return this;
159
- }
160
- flushShared() {
161
- this.sharedData = {};
162
- return this;
163
- }
164
- flushComposers() {
165
- this.composers.clear();
166
- return this;
167
- }
168
- getComposers(name) {
169
- const edgeName = this.resolveName(name);
170
- return [
171
- ...this.composers.get("*") ?? [],
172
- ...this.composers.get(edgeName) ?? [],
173
- ...this.composers.get(name) ?? []
174
- ];
175
- }
176
- async runComposers(name, view) {
177
- for (const composer of this.getComposers(name)) await runComposer(composer, view);
178
- }
179
- runComposersSync(name, view) {
180
- for (const composer of this.getComposers(name)) runComposerSync(composer, view);
181
- }
182
- resolveName(name) {
183
- const packageView = parsePackageViewName(name);
184
- if (!packageView) return name;
185
- if (!this.mountedPackages.has(packageView.diskName)) {
186
- this.mount(packageView.diskName, resolvePackageViewsPath(packageView.nodePackageName, this.packageViewsPath));
187
- this.mountedPackages.add(packageView.diskName);
188
- }
189
- return packageView.edgeName;
190
- }
191
- };
192
- //#endregion
193
- //#region src/View.ts
194
- var View = class View {
195
- static factory = new ViewFactory();
196
- /**
197
- * Bootstrap the view service
198
- */
199
- static boot() {
200
- Object.defineProperty(globalThis, "view", {
201
- value: (name, data = {}) => {
202
- if (name === void 0) return View.factoryInstance();
203
- return View.make(name, data);
204
- },
205
- configurable: true,
206
- writable: true
207
- });
208
- }
209
- static configure(options = {}) {
210
- this.factory = new ViewFactory(options);
211
- return this.factory;
212
- }
213
- static factoryInstance() {
214
- return this.factory;
215
- }
216
- static make(name, data = {}) {
217
- return this.factory.make(name, data);
218
- }
219
- static first(names, data = {}) {
220
- return this.factory.first(names, data);
221
- }
222
- static exists(name) {
223
- return this.factory.exists(name);
224
- }
225
- static share(...data) {
226
- if (typeof data[0] === "string") this.factory.share(data[0], data[1]);
227
- else this.factory.share(data[0] ?? {});
228
- return this;
229
- }
230
- static composer(names, composer) {
231
- this.factory.composer(names, composer);
232
- return this;
233
- }
234
- static mount(diskName, viewsDirectory) {
235
- if (viewsDirectory === void 0) this.factory.mount(diskName);
236
- else this.factory.mount(diskName, viewsDirectory);
237
- return this;
238
- }
239
- static raw(name, contents) {
240
- this.factory.raw(name, contents);
241
- return this;
242
- }
243
- };
244
- //#endregion
245
- export { Edge, View, ViewFactory, ViewInstance, edge, parsePackageViewName, resolvePackageViewsPath, view };
246
-
247
- //# sourceMappingURL=index.js.map
1
+ import { a as collectViewData, c as runWithViewData, d as resolvePackageViewsPath, f as view, i as clearViewData, l as ViewInstance, m as normalizeViewErrors, n as View, o as enterViewData, p as ViewErrorBag, r as ViewFactory, s as getViewData, t as clearRouterViewPlugin, u as parsePackageViewName } from "./plugins-OaO2BC-T.js";
2
+ import edge, { Edge } from "edge.js";
3
+ export { Edge, View, ViewErrorBag, ViewFactory, ViewInstance, clearRouterViewPlugin, clearViewData, collectViewData, edge, enterViewData, getViewData, normalizeViewErrors, parsePackageViewName, resolvePackageViewsPath, runWithViewData, view };
@@ -0,0 +1,7 @@
1
+ import * as _$clear_router_core0 from "clear-router/core";
2
+
3
+ //#region src/plugins.d.ts
4
+ declare const clearRouterViewPlugin: _$clear_router_core0.ClearRouterPlugin<any, any>;
5
+ //#endregion
6
+ export { clearRouterViewPlugin as t };
7
+ //# sourceMappingURL=plugins-D3vyoc8i.d.ts.map
@@ -0,0 +1,460 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { Edge } from "edge.js";
4
+ import { AsyncLocalStorage } from "node:async_hooks";
5
+ import { definePlugin } from "clear-router/core";
6
+ //#region src/ViewErrorBag.ts
7
+ const defaultErrorKey = "_";
8
+ var ViewErrorBag = class ViewErrorBag {
9
+ bag = {};
10
+ constructor(errors) {
11
+ if (errors) this.merge(errors);
12
+ }
13
+ add(field, message) {
14
+ const key = field || defaultErrorKey;
15
+ const messages = toMessages(message);
16
+ if (!messages.length) return this;
17
+ this.bag[key] = [...this.bag[key] || [], ...messages];
18
+ return this;
19
+ }
20
+ merge(errors) {
21
+ const incoming = errors instanceof ViewErrorBag ? errors.toJSON() : getMessageRecord(errors) || (isRecord(errors) ? errors : void 0);
22
+ if (!incoming) return this;
23
+ for (const [field, messages] of Object.entries(incoming)) this.add(field, messages);
24
+ return this;
25
+ }
26
+ keys() {
27
+ return Object.keys(this.bag);
28
+ }
29
+ get(field = defaultErrorKey) {
30
+ return [...this.bag[field] || []];
31
+ }
32
+ first(field) {
33
+ if (field) return this.bag[field]?.[0] || "";
34
+ return this.all()[0] || "";
35
+ }
36
+ has(field) {
37
+ if (Array.isArray(field)) return field.every((key) => this.has(key));
38
+ if (field) return (this.bag[field]?.length || 0) > 0;
39
+ return this.any();
40
+ }
41
+ hasAny(fields) {
42
+ return (Array.isArray(fields) ? fields : [fields]).some((key) => this.has(key));
43
+ }
44
+ missing(fields) {
45
+ return (Array.isArray(fields) ? fields : [fields]).every((key) => !this.has(key));
46
+ }
47
+ any() {
48
+ return Object.values(this.bag).some((messages) => messages.length > 0);
49
+ }
50
+ isEmpty() {
51
+ return !this.any();
52
+ }
53
+ isNotEmpty() {
54
+ return this.any();
55
+ }
56
+ count() {
57
+ return Object.values(this.bag).reduce((total, messages) => total + messages.length, 0);
58
+ }
59
+ all() {
60
+ return Object.values(this.bag).flat();
61
+ }
62
+ unique() {
63
+ return [...new Set(this.all())];
64
+ }
65
+ clear(field) {
66
+ if (Array.isArray(field)) {
67
+ for (const key of field) delete this.bag[key];
68
+ return this;
69
+ }
70
+ if (field) {
71
+ delete this.bag[field];
72
+ return this;
73
+ }
74
+ this.bag = {};
75
+ return this;
76
+ }
77
+ forget(field) {
78
+ return this.clear(field);
79
+ }
80
+ messagesRaw() {
81
+ return this.toJSON();
82
+ }
83
+ getMessages() {
84
+ return this.messagesRaw();
85
+ }
86
+ getMessageBag() {
87
+ return this;
88
+ }
89
+ toArray() {
90
+ return this.toJSON();
91
+ }
92
+ toJSON() {
93
+ return Object.entries(this.bag).reduce((errors, [field, messages]) => {
94
+ errors[field] = [...messages];
95
+ return errors;
96
+ }, {});
97
+ }
98
+ };
99
+ const isViewErrorBag = (value) => {
100
+ return isRecord(value) && typeof value.all === "function" && typeof value.first === "function" && typeof value.get === "function" && typeof value.has === "function";
101
+ };
102
+ const normalizeViewErrors = (errors) => {
103
+ if (isViewErrorBag(errors)) return errors;
104
+ return new ViewErrorBag(errors);
105
+ };
106
+ //#endregion
107
+ //#region src/helpers.ts
108
+ function view(name, data = {}) {
109
+ if (name === void 0) return View.factoryInstance();
110
+ return View.make(name, data);
111
+ }
112
+ const isClass = (target) => {
113
+ return typeof target === "function" && /^class\s/.test(Function.prototype.toString.call(target));
114
+ };
115
+ const currentHttpSession = () => {
116
+ try {
117
+ const session = globalThis.session?.();
118
+ return session && typeof session === "object" ? session : void 0;
119
+ } catch {
120
+ return;
121
+ }
122
+ };
123
+ const hasRenderableErrors = (errors) => {
124
+ if (!errors || typeof errors !== "object") return false;
125
+ const bag = errors;
126
+ if (typeof bag.any === "function") return Boolean(bag.any());
127
+ if (typeof bag.has === "function") return Boolean(bag.has());
128
+ if (typeof bag.isNotEmpty === "function") return Boolean(bag.isNotEmpty());
129
+ if (typeof bag.all === "function") {
130
+ const messages = bag.all();
131
+ if (Array.isArray(messages)) return messages.length > 0;
132
+ return !!messages && typeof messages === "object" && Object.keys(messages).length > 0;
133
+ }
134
+ return Object.keys(bag).length > 0;
135
+ };
136
+ const normalizeViewData = (data = {}) => {
137
+ const session = currentHttpSession();
138
+ const ownErrors = normalizeViewErrors(data.errors);
139
+ const sessionErrors = session?.errors;
140
+ const errors = hasRenderableErrors(ownErrors) || !sessionErrors ? ownErrors : normalizeViewErrors(sessionErrors);
141
+ return {
142
+ ...session && !("session" in data) ? { session } : {},
143
+ ...session && !("httpSession" in data) ? { httpSession: session } : {},
144
+ ...data,
145
+ errors
146
+ };
147
+ };
148
+ const mergeData = (target, data) => {
149
+ if (data.length === 0) return target;
150
+ if (typeof data[0] === "string") {
151
+ target[data[0]] = data[0] === "errors" ? normalizeViewErrors(data[1]) : data[1];
152
+ return target;
153
+ }
154
+ for (const value of data) if (value && typeof value === "object" && !Array.isArray(value)) Object.assign(target, normalizeViewData(value));
155
+ return target;
156
+ };
157
+ const runComposerSync = (composer, view) => {
158
+ const result = runComposer(composer, view);
159
+ if (result && typeof result.then === "function") throw new Error("Async view composers cannot be used with renderSync.");
160
+ };
161
+ const runComposer = (composer, view) => {
162
+ if (typeof composer === "function") {
163
+ if (isClass(composer)) return new composer().compose(view);
164
+ return composer(view);
165
+ }
166
+ return composer.compose(view);
167
+ };
168
+ const isRecord = (value) => {
169
+ return !!value && typeof value === "object" && !Array.isArray(value);
170
+ };
171
+ const toMessages = (value) => {
172
+ if (Array.isArray(value)) return value.flatMap((item) => toMessages(item));
173
+ if (value instanceof Error) return [value.message];
174
+ if (isRecord(value) && typeof value.message === "string") return [value.message];
175
+ if (value === null || typeof value === "undefined") return [];
176
+ return [String(value)];
177
+ };
178
+ const getMessageRecord = (source) => {
179
+ if (!isRecord(source)) return;
180
+ if (typeof source.getMessageBag === "function") {
181
+ const bag = source.getMessageBag();
182
+ if (bag && bag !== source) {
183
+ const messages = getMessageRecord(bag);
184
+ if (messages) return messages;
185
+ }
186
+ }
187
+ for (const method of [
188
+ "getMessages",
189
+ "messagesRaw",
190
+ "toArray"
191
+ ]) if (typeof source[method] === "function") {
192
+ const messages = source[method]();
193
+ if (isRecord(messages)) return messages;
194
+ }
195
+ if (typeof source.errors === "function") {
196
+ const errors = source.errors();
197
+ const messages = getMessageRecord(errors) || (isRecord(errors) ? errors : void 0);
198
+ if (messages) return messages;
199
+ }
200
+ return getMessageRecord(source.errors) || (isRecord(source.errors) ? source.errors : void 0);
201
+ };
202
+ //#endregion
203
+ //#region src/packageViews.ts
204
+ const parsePackageViewName = (name) => {
205
+ if (!name.startsWith("~")) return null;
206
+ const source = name.slice(1);
207
+ const slashIndex = source.indexOf("/");
208
+ const dotIndex = slashIndex === -1 ? source.indexOf(".") : source.indexOf(".", slashIndex);
209
+ if (dotIndex <= 0) throw new Error(`Invalid package view name: ${name}`);
210
+ const packageName = source.slice(0, dotIndex);
211
+ const viewName = source.slice(dotIndex + 1);
212
+ if (!viewName) throw new Error(`Invalid package view name: ${name}`);
213
+ const nodePackageName = slashIndex === -1 ? packageName : `@${packageName}`;
214
+ const diskName = `package_${packageName.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
215
+ return {
216
+ source: name,
217
+ packageName,
218
+ nodePackageName,
219
+ diskName,
220
+ viewName,
221
+ edgeName: `${diskName}::${viewName}`
222
+ };
223
+ };
224
+ const resolvePackageViewsPath = (nodePackageName, viewPath = "resources/views") => {
225
+ const viewsPath = resolve(resolve(process.cwd(), "node_modules", nodePackageName), viewPath);
226
+ if (!existsSync(viewsPath)) throw new Error(`Package views directory not found: ${viewsPath}`);
227
+ return viewsPath;
228
+ };
229
+ //#endregion
230
+ //#region src/ViewInstance.ts
231
+ var ViewInstance = class {
232
+ name;
233
+ renderer;
234
+ runComposers;
235
+ runComposersSync;
236
+ renderName;
237
+ payload;
238
+ composersHaveRun = false;
239
+ constructor(name, data = {}, renderer, runComposers, runComposersSync, renderName = name) {
240
+ this.name = name;
241
+ this.renderer = renderer;
242
+ this.runComposers = runComposers;
243
+ this.runComposersSync = runComposersSync;
244
+ this.renderName = renderName;
245
+ this.payload = normalizeViewData({ ...data });
246
+ }
247
+ get data() {
248
+ return this.payload;
249
+ }
250
+ with(...data) {
251
+ mergeData(this.payload, data);
252
+ return this;
253
+ }
254
+ async render() {
255
+ await this.compose();
256
+ return await this.renderer.render(this.renderName, this.payload);
257
+ }
258
+ renderSync() {
259
+ this.composeSync();
260
+ return this.renderer.renderSync(this.renderName, this.payload);
261
+ }
262
+ then(onfulfilled, onrejected) {
263
+ return this.render().then(onfulfilled, onrejected);
264
+ }
265
+ async compose() {
266
+ if (this.composersHaveRun) return;
267
+ this.composersHaveRun = true;
268
+ await this.runComposers(this);
269
+ }
270
+ composeSync() {
271
+ if (this.composersHaveRun) return;
272
+ this.composersHaveRun = true;
273
+ this.runComposersSync(this);
274
+ }
275
+ };
276
+ //#endregion
277
+ //#region src/viewContext.ts
278
+ const store = new AsyncLocalStorage();
279
+ const normalizeContextData = (data = {}) => normalizeViewData(data);
280
+ const getViewData = () => store.getStore() || {};
281
+ const enterViewData = (data = {}) => {
282
+ store.enterWith(normalizeContextData({
283
+ ...getViewData(),
284
+ ...data
285
+ }));
286
+ };
287
+ const runWithViewData = async (data, callback) => {
288
+ return await store.run(normalizeContextData(data), callback);
289
+ };
290
+ const clearViewData = () => {
291
+ store.disable();
292
+ };
293
+ const collectViewData = (context) => {
294
+ const ctx = isRecord(context.ctx) ? context.ctx : context;
295
+ const response = isRecord(context.response) ? context.response : void 0;
296
+ const locals = {
297
+ ...isRecord(ctx.res?.locals) ? ctx.res.locals : {},
298
+ ...isRecord(ctx.response?.source?.locals) ? ctx.response.source.locals : {},
299
+ ...isRecord(response?.source?.locals) ? response.source.locals : {}
300
+ };
301
+ return normalizeContextData({
302
+ ..."session" in ctx ? { session: ctx.session } : {},
303
+ ..."httpSession" in ctx ? { httpSession: ctx.httpSession } : {},
304
+ ..."errors" in ctx ? { errors: ctx.errors } : {},
305
+ ...locals
306
+ });
307
+ };
308
+ //#endregion
309
+ //#region src/ViewFactory.ts
310
+ var ViewFactory = class {
311
+ edge;
312
+ sharedData = {};
313
+ composers = /* @__PURE__ */ new Map();
314
+ mountedPackages = /* @__PURE__ */ new Set();
315
+ packageViewsPath;
316
+ constructor(options = {}) {
317
+ this.edge = options.edge ?? Edge.create({ cache: options.cache });
318
+ this.packageViewsPath = options.packageViewsPath ?? "resources/views";
319
+ this.mount(options.viewsPath ?? resolve(process.cwd(), "src", "resources", "views"));
320
+ }
321
+ make(name, data = {}) {
322
+ const edgeName = this.resolveName(name);
323
+ return new ViewInstance(name, normalizeViewData({
324
+ ...this.sharedData,
325
+ ...getViewData(),
326
+ ...data
327
+ }), this.edge, async (view) => await this.runComposers(name, view), (view) => this.runComposersSync(name, view), edgeName);
328
+ }
329
+ first(names, data = {}) {
330
+ const name = names.find((candidate) => this.exists(candidate));
331
+ if (!name) throw new Error(`None of the given views exist: ${names.join(", ")}`);
332
+ return this.make(name, data);
333
+ }
334
+ exists(name) {
335
+ const edgeName = this.resolveName(name);
336
+ if (this.edge.loader.templates[edgeName]) return true;
337
+ try {
338
+ return existsSync(this.edge.loader.makePath(edgeName));
339
+ } catch {
340
+ return false;
341
+ }
342
+ }
343
+ share(...data) {
344
+ mergeData(this.sharedData, data);
345
+ return this;
346
+ }
347
+ composer(names, composer) {
348
+ for (const name of Array.isArray(names) ? names : [names]) this.composers.set(name, [...this.composers.get(name) ?? [], composer]);
349
+ return this;
350
+ }
351
+ mount(diskName, viewsDirectory) {
352
+ if (viewsDirectory === void 0) {
353
+ this.edge.mount(diskName);
354
+ return this;
355
+ }
356
+ this.edge.mount(diskName, viewsDirectory);
357
+ return this;
358
+ }
359
+ raw(name, contents) {
360
+ this.edge.registerTemplate(name, { template: contents });
361
+ return this;
362
+ }
363
+ flushShared() {
364
+ this.sharedData = {};
365
+ return this;
366
+ }
367
+ flushComposers() {
368
+ this.composers.clear();
369
+ return this;
370
+ }
371
+ getComposers(name) {
372
+ const edgeName = this.resolveName(name);
373
+ return [
374
+ ...this.composers.get("*") ?? [],
375
+ ...this.composers.get(edgeName) ?? [],
376
+ ...this.composers.get(name) ?? []
377
+ ];
378
+ }
379
+ async runComposers(name, view) {
380
+ for (const composer of this.getComposers(name)) await runComposer(composer, view);
381
+ }
382
+ runComposersSync(name, view) {
383
+ for (const composer of this.getComposers(name)) runComposerSync(composer, view);
384
+ }
385
+ resolveName(name) {
386
+ const packageView = parsePackageViewName(name);
387
+ if (!packageView) return name;
388
+ if (!this.mountedPackages.has(packageView.diskName)) {
389
+ this.mount(packageView.diskName, resolvePackageViewsPath(packageView.nodePackageName, this.packageViewsPath));
390
+ this.mountedPackages.add(packageView.diskName);
391
+ }
392
+ return packageView.edgeName;
393
+ }
394
+ };
395
+ //#endregion
396
+ //#region src/View.ts
397
+ var View = class View {
398
+ static factory = new ViewFactory();
399
+ /**
400
+ * Bootstrap the view service
401
+ */
402
+ static boot() {
403
+ Object.defineProperty(globalThis, "view", {
404
+ value: (name, data = {}) => {
405
+ if (name === void 0) return View.factoryInstance();
406
+ return View.make(name, data);
407
+ },
408
+ configurable: true,
409
+ writable: true
410
+ });
411
+ }
412
+ static configure(options = {}) {
413
+ this.factory = new ViewFactory(options);
414
+ return this.factory;
415
+ }
416
+ static factoryInstance() {
417
+ return this.factory;
418
+ }
419
+ static make(name, data = {}) {
420
+ return this.factory.make(name, data);
421
+ }
422
+ static first(names, data = {}) {
423
+ return this.factory.first(names, data);
424
+ }
425
+ static exists(name) {
426
+ return this.factory.exists(name);
427
+ }
428
+ static share(...data) {
429
+ if (typeof data[0] === "string") this.factory.share(data[0], data[1]);
430
+ else this.factory.share(data[0] ?? {});
431
+ return this;
432
+ }
433
+ static composer(names, composer) {
434
+ this.factory.composer(names, composer);
435
+ return this;
436
+ }
437
+ static mount(diskName, viewsDirectory) {
438
+ if (viewsDirectory === void 0) this.factory.mount(diskName);
439
+ else this.factory.mount(diskName, viewsDirectory);
440
+ return this;
441
+ }
442
+ static raw(name, contents) {
443
+ this.factory.raw(name, contents);
444
+ return this;
445
+ }
446
+ };
447
+ //#endregion
448
+ //#region src/plugins.ts
449
+ const clearRouterViewPlugin = definePlugin({
450
+ name: "arkstack-view",
451
+ setup: ({ useHttpContext }) => {
452
+ useHttpContext((context) => {
453
+ enterViewData(collectViewData(context));
454
+ });
455
+ }
456
+ });
457
+ //#endregion
458
+ export { collectViewData as a, runWithViewData as c, resolvePackageViewsPath as d, view as f, clearViewData as i, ViewInstance as l, normalizeViewErrors as m, View as n, enterViewData as o, ViewErrorBag as p, ViewFactory as r, getViewData as s, clearRouterViewPlugin as t, parsePackageViewName as u };
459
+
460
+ //# sourceMappingURL=plugins-OaO2BC-T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins-OaO2BC-T.js","names":["defineClearRouterPlugin"],"sources":["../src/ViewErrorBag.ts","../src/helpers.ts","../src/packageViews.ts","../src/ViewInstance.ts","../src/viewContext.ts","../src/ViewFactory.ts","../src/View.ts","../src/plugins.ts"],"sourcesContent":["import { ViewErrorRecord, ViewErrorValue } from './types'\nimport { getMessageRecord, isRecord, toMessages } from './helpers'\n\nconst defaultErrorKey = '_'\n\nexport class ViewErrorBag {\n private bag: Record<string, string[]> = {}\n\n constructor(errors?: ViewErrorRecord | ViewErrorBag | unknown) {\n if (errors) {\n this.merge(errors)\n }\n }\n\n add (field: string, message: ViewErrorValue) {\n const key = field || defaultErrorKey\n const messages = toMessages(message)\n\n if (!messages.length) {\n return this\n }\n\n this.bag[key] = [\n ...(this.bag[key] || []),\n ...messages,\n ]\n\n return this\n }\n\n merge (errors: ViewErrorRecord | ViewErrorBag | unknown) {\n const incoming = errors instanceof ViewErrorBag\n ? errors.toJSON()\n : getMessageRecord(errors) || (isRecord(errors) ? errors as ViewErrorRecord : undefined)\n\n if (!incoming) {\n return this\n }\n\n for (const [field, messages] of Object.entries(incoming)) {\n this.add(field, messages)\n }\n\n return this\n }\n\n keys () {\n return Object.keys(this.bag)\n }\n\n get (field: string = defaultErrorKey) {\n return [...(this.bag[field] || [])]\n }\n\n first (field?: string | null) {\n if (field) {\n return this.bag[field]?.[0] || ''\n }\n\n return this.all()[0] || ''\n }\n\n has (field?: string | string[] | null): boolean {\n if (Array.isArray(field)) {\n return field.every(key => this.has(key))\n }\n\n if (field) {\n return (this.bag[field]?.length || 0) > 0\n }\n\n return this.any()\n }\n\n hasAny (fields: string | string[]) {\n const keys = Array.isArray(fields) ? fields : [fields]\n\n return keys.some(key => this.has(key))\n }\n\n missing (fields: string | string[]) {\n const keys = Array.isArray(fields) ? fields : [fields]\n\n return keys.every(key => !this.has(key))\n }\n\n any () {\n return Object.values(this.bag).some(messages => messages.length > 0)\n }\n\n isEmpty () {\n return !this.any()\n }\n\n isNotEmpty () {\n return this.any()\n }\n\n count () {\n return Object.values(this.bag).reduce((total, messages) => total + messages.length, 0)\n }\n\n all () {\n return Object.values(this.bag).flat()\n }\n\n unique () {\n return [...new Set(this.all())]\n }\n\n clear (field?: string | string[]) {\n if (Array.isArray(field)) {\n for (const key of field) {\n delete this.bag[key]\n }\n\n return this\n }\n\n if (field) {\n delete this.bag[field]\n\n return this\n }\n\n this.bag = {}\n\n return this\n }\n\n forget (field: string) {\n return this.clear(field)\n }\n\n messagesRaw () {\n return this.toJSON()\n }\n\n getMessages () {\n return this.messagesRaw()\n }\n\n getMessageBag () {\n return this\n }\n\n toArray () {\n return this.toJSON()\n }\n\n toJSON () {\n return Object\n .entries(this.bag)\n .reduce<Record<string, string[]>>((errors, [field, messages]) => {\n errors[field] = [...messages]\n\n return errors\n }, {})\n }\n}\n\nexport const isViewErrorBag = (value: unknown): value is Pick<ViewErrorBag, 'all' | 'first' | 'get' | 'has'> => {\n return isRecord(value)\n && typeof value.all === 'function'\n && typeof value.first === 'function'\n && typeof value.get === 'function'\n && typeof value.has === 'function'\n}\n\nexport const normalizeViewErrors = (errors?: unknown) => {\n if (isViewErrorBag(errors)) {\n return errors\n }\n\n return new ViewErrorBag(errors)\n}\n","import type { ViewComposer, ViewComposerObject, ViewData, ViewErrorRecord, ViewErrorValue, ViewName } from './types'\n\nimport { View } from './View'\nimport { ViewFactory } from './ViewFactory'\nimport { ViewInstance } from './ViewInstance'\nimport { normalizeViewErrors } from './ViewErrorBag'\n\nexport function view (): ViewFactory\nexport function view (name: ViewName, data?: ViewData): ViewInstance\nexport function view (name?: ViewName, data: ViewData = {}) {\n if (name === undefined) {\n return View.factoryInstance()\n }\n\n return View.make(name, data)\n}\n\nexport const isClass = <T = unknown> (\n target: unknown\n): target is new (...args: any[]) => T => {\n return typeof target === 'function'\n && /^class\\s/.test(Function.prototype.toString.call(target))\n}\n\nconst currentHttpSession = () => {\n try {\n const session = globalThis.session?.()\n\n return session && typeof session === 'object' ? session as Record<string, any> : undefined\n } catch {\n return undefined\n }\n}\n\nconst hasRenderableErrors = (errors: unknown) => {\n if (!errors || typeof errors !== 'object') {\n return false\n }\n\n const bag = errors as Record<string, any>\n\n if (typeof bag.any === 'function') {\n return Boolean(bag.any())\n }\n\n if (typeof bag.has === 'function') {\n return Boolean(bag.has())\n }\n\n if (typeof bag.isNotEmpty === 'function') {\n return Boolean(bag.isNotEmpty())\n }\n\n if (typeof bag.all === 'function') {\n const messages = bag.all()\n\n if (Array.isArray(messages)) {\n return messages.length > 0\n }\n\n return !!messages && typeof messages === 'object' && Object.keys(messages).length > 0\n }\n\n return Object.keys(bag).length > 0\n}\n\nexport const normalizeViewData = (data: ViewData = {}) => {\n const session = currentHttpSession()\n const ownErrors = normalizeViewErrors(data.errors)\n const sessionErrors = session?.errors\n const errors = hasRenderableErrors(ownErrors) || !sessionErrors\n ? ownErrors\n : normalizeViewErrors(sessionErrors)\n\n return {\n ...(session && !('session' in data) ? { session } : {}),\n ...(session && !('httpSession' in data) ? { httpSession: session } : {}),\n ...data,\n errors,\n }\n}\n\nexport const mergeData = (target: ViewData, data: any[]) => {\n if (data.length === 0) {\n return target\n }\n\n if (typeof data[0] === 'string') {\n target[data[0]] = data[0] === 'errors' ? normalizeViewErrors(data[1]) : data[1]\n\n return target\n }\n\n for (const value of data) {\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n Object.assign(target, normalizeViewData(value))\n }\n }\n\n return target\n}\n\nexport const runComposerSync = (composer: ViewComposer, view: ViewInstance) => {\n const result = runComposer(composer, view)\n\n if (result && typeof result.then === 'function') {\n throw new Error('Async view composers cannot be used with renderSync.')\n }\n}\n\nexport const runComposer = (composer: ViewComposer, view: ViewInstance) => {\n if (typeof composer === 'function') {\n if (isClass<ViewComposerObject>(composer)) {\n return new composer().compose(view)\n }\n\n return composer(view)\n }\n\n return composer.compose(view)\n}\n\nexport const isRecord = (value: unknown): value is Record<string, any> => {\n return !!value && typeof value === 'object' && !Array.isArray(value)\n}\n\nexport const toMessages = (value: ViewErrorValue): string[] => {\n if (Array.isArray(value)) {\n return value.flatMap(item => toMessages(item))\n }\n\n if (value instanceof Error) {\n return [value.message]\n }\n\n if (isRecord(value) && typeof value.message === 'string') {\n return [value.message]\n }\n\n if (value === null || typeof value === 'undefined') {\n return []\n }\n\n return [String(value)]\n}\n\nexport const getMessageRecord = (source: unknown): ViewErrorRecord | undefined => {\n if (!isRecord(source)) {\n return undefined\n }\n\n if (typeof source.getMessageBag === 'function') {\n const bag = source.getMessageBag()\n\n if (bag && bag !== source) {\n const messages = getMessageRecord(bag)\n\n if (messages) {\n return messages\n }\n }\n }\n\n for (const method of ['getMessages', 'messagesRaw', 'toArray']) {\n if (typeof source[method] === 'function') {\n const messages = source[method]()\n\n if (isRecord(messages)) {\n return messages\n }\n }\n }\n\n if (typeof source.errors === 'function') {\n const errors = source.errors()\n const messages = getMessageRecord(errors) || (isRecord(errors) ? errors : undefined)\n\n if (messages) {\n return messages\n }\n }\n\n return getMessageRecord(source.errors) || (isRecord(source.errors) ? source.errors : undefined)\n}","import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nexport type PackageViewReference = {\n source: string\n packageName: string\n nodePackageName: string\n diskName: string\n viewName: string\n edgeName: string\n}\n\nexport const parsePackageViewName = (name: string): PackageViewReference | null => {\n if (!name.startsWith('~')) {\n return null\n }\n\n const source = name.slice(1)\n const slashIndex = source.indexOf('/')\n const dotIndex = slashIndex === -1\n ? source.indexOf('.')\n : source.indexOf('.', slashIndex)\n\n if (dotIndex <= 0) {\n throw new Error(`Invalid package view name: ${name}`)\n }\n\n const packageName = source.slice(0, dotIndex)\n const viewName = source.slice(dotIndex + 1)\n\n if (!viewName) {\n throw new Error(`Invalid package view name: ${name}`)\n }\n\n const nodePackageName = slashIndex === -1\n ? packageName\n : `@${packageName}`\n const diskName = `package_${packageName.replace(/[^a-zA-Z0-9_-]/g, '_')}`\n\n return {\n source: name,\n packageName,\n nodePackageName,\n diskName,\n viewName,\n edgeName: `${diskName}::${viewName}`,\n }\n}\n\nexport const resolvePackageViewsPath = (\n nodePackageName: string,\n viewPath = 'resources/views',\n) => {\n const packageRoot = resolve(process.cwd(), 'node_modules', nodePackageName)\n const viewsPath = resolve(packageRoot, viewPath)\n\n if (!existsSync(viewsPath)) {\n throw new Error(`Package views directory not found: ${viewsPath}`)\n }\n\n return viewsPath\n}\n","import type { ComposerRunner, SyncComposerRunner, ViewData } from './types'\n\nimport { mergeData, normalizeViewData } from './helpers'\n\nexport class ViewInstance implements PromiseLike<string> {\n private payload: ViewData\n private composersHaveRun = false\n\n constructor(\n readonly name: string,\n data: ViewData = {},\n private renderer: {\n render: (name: string, data?: ViewData) => Promise<string>\n renderSync: (name: string, data?: ViewData) => string\n },\n private runComposers: ComposerRunner,\n private runComposersSync: SyncComposerRunner,\n private renderName = name,\n ) {\n this.payload = normalizeViewData({ ...data })\n }\n\n get data () {\n return this.payload\n }\n\n with (key: string, value: any): this\n with (data: ViewData): this\n with (...data: any[]): this {\n mergeData(this.payload, data)\n\n return this\n }\n\n async render () {\n await this.compose()\n\n return await this.renderer.render(this.renderName, this.payload)\n }\n\n renderSync () {\n this.composeSync()\n\n return this.renderer.renderSync(this.renderName, this.payload)\n }\n\n then<TResult1 = string, TResult2 = never> (\n onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,\n ): PromiseLike<TResult1 | TResult2> {\n return this.render().then(onfulfilled, onrejected)\n }\n\n private async compose () {\n if (this.composersHaveRun) {\n return\n }\n\n this.composersHaveRun = true\n await this.runComposers(this)\n }\n\n private composeSync () {\n if (this.composersHaveRun) {\n return\n }\n\n this.composersHaveRun = true\n this.runComposersSync(this)\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks'\nimport type { ViewData } from './types'\nimport { isRecord, normalizeViewData } from './helpers'\n\nconst store = new AsyncLocalStorage<ViewData>()\n\nconst normalizeContextData = (data: ViewData = {}) => normalizeViewData(data)\n\nexport const getViewData = () => store.getStore() || {}\n\nexport const enterViewData = (data: ViewData = {}) => {\n store.enterWith(normalizeContextData({ ...getViewData(), ...data }))\n}\n\nexport const runWithViewData = async <T> (data: ViewData, callback: () => T | Promise<T>) => {\n return await store.run(normalizeContextData(data), callback)\n}\n\nexport const clearViewData = () => {\n store.disable()\n}\n\nexport const collectViewData = (context: Record<string, any>): ViewData => {\n const ctx = isRecord(context.ctx) ? context.ctx : context\n const response = isRecord(context.response) ? context.response : undefined\n const locals = {\n ...(isRecord(ctx.res?.locals) ? ctx.res.locals : {}),\n ...(isRecord(ctx.response?.source?.locals) ? ctx.response.source.locals : {}),\n ...(isRecord(response?.source?.locals) ? response.source.locals : {}),\n }\n\n return normalizeContextData({\n ...('session' in ctx ? { session: ctx.session } : {}),\n ...('httpSession' in ctx ? { httpSession: ctx.httpSession } : {}),\n ...('errors' in ctx ? { errors: ctx.errors } : {}),\n ...locals,\n })\n}\n","import type { ViewComposer, ViewComposerName, ViewData, ViewFactoryOptions, ViewName } from './types'\nimport { mergeData, normalizeViewData, runComposer, runComposerSync } from './helpers'\nimport { parsePackageViewName, resolvePackageViewsPath } from './packageViews'\n\nimport { Edge } from 'edge.js'\nimport { ViewInstance } from './ViewInstance'\nimport { existsSync } from 'node:fs'\nimport { getViewData } from './viewContext'\nimport { resolve } from 'node:path'\n\nexport class ViewFactory {\n readonly edge: Edge\n private sharedData: ViewData = {}\n private composers = new Map<ViewName, ViewComposer[]>()\n private mountedPackages = new Set<string>()\n private packageViewsPath: string\n\n constructor(options: ViewFactoryOptions = {}) {\n this.edge = options.edge ?? Edge.create({ cache: options.cache })\n this.packageViewsPath = options.packageViewsPath ?? 'resources/views'\n this.mount(options.viewsPath ?? resolve(process.cwd(), 'src', 'resources', 'views'))\n }\n\n make (name: ViewName, data: ViewData = {}) {\n const edgeName = this.resolveName(name)\n\n return new ViewInstance(\n name,\n normalizeViewData({ ...this.sharedData, ...getViewData(), ...data }),\n this.edge,\n async view => await this.runComposers(name, view),\n view => this.runComposersSync(name, view),\n edgeName,\n )\n }\n\n first (names: ViewName[], data: ViewData = {}) {\n const name = names.find(candidate => this.exists(candidate))\n\n if (!name) {\n throw new Error(`None of the given views exist: ${names.join(', ')}`)\n }\n\n return this.make(name, data)\n }\n\n exists (name: ViewName) {\n const edgeName = this.resolveName(name)\n\n if (this.edge.loader.templates[edgeName]) {\n return true\n }\n\n try {\n return existsSync(this.edge.loader.makePath(edgeName))\n } catch {\n return false\n }\n }\n\n share (key: string, value: any): this\n share (data: ViewData): this\n share (...data: any[]): this {\n mergeData(this.sharedData, data)\n\n return this\n }\n\n composer (names: ViewComposerName, composer: ViewComposer): this {\n for (const name of Array.isArray(names) ? names : [names]) {\n this.composers.set(name, [\n ...(this.composers.get(name) ?? []),\n composer,\n ])\n }\n\n return this\n }\n\n mount (viewsDirectory: string | URL): this\n mount (diskName: string, viewsDirectory: string | URL): this\n mount (diskName: string | URL, viewsDirectory?: string | URL): this {\n if (viewsDirectory === undefined) {\n this.edge.mount(diskName)\n\n return this\n }\n\n this.edge.mount(diskName as string, viewsDirectory)\n\n return this\n }\n\n raw (name: ViewName, contents: string): this {\n this.edge.registerTemplate(name, { template: contents })\n\n return this\n }\n\n flushShared () {\n this.sharedData = {}\n\n return this\n }\n\n flushComposers () {\n this.composers.clear()\n\n return this\n }\n\n private getComposers (name: ViewName) {\n const edgeName = this.resolveName(name)\n\n return [\n ...(this.composers.get('*') ?? []),\n ...(this.composers.get(edgeName) ?? []),\n ...(this.composers.get(name) ?? []),\n ]\n }\n\n private async runComposers (name: ViewName, view: ViewInstance) {\n for (const composer of this.getComposers(name)) {\n await runComposer(composer, view)\n }\n }\n\n private runComposersSync (name: ViewName, view: ViewInstance) {\n for (const composer of this.getComposers(name)) {\n runComposerSync(composer, view)\n }\n }\n\n private resolveName (name: ViewName) {\n const packageView = parsePackageViewName(name)\n\n if (!packageView) {\n return name\n }\n\n if (!this.mountedPackages.has(packageView.diskName)) {\n this.mount(\n packageView.diskName,\n resolvePackageViewsPath(packageView.nodePackageName, this.packageViewsPath),\n )\n this.mountedPackages.add(packageView.diskName)\n }\n\n return packageView.edgeName\n }\n}\n","import type { ViewComposer, ViewComposerName, ViewData, ViewFactoryOptions, ViewName } from './types'\n\nimport { ViewFactory } from './ViewFactory'\nimport type { ViewInstance } from './ViewInstance'\n\nexport class View {\n private static factory = new ViewFactory()\n\n /**\n * Bootstrap the view service\n */\n static boot () {\n Object.defineProperty(globalThis, 'view', {\n value: (name?: ViewName, data: ViewData = {}) => {\n if (name === undefined) {\n return View.factoryInstance()\n }\n\n return View.make(name, data)\n },\n configurable: true,\n writable: true,\n })\n }\n\n static configure (options: ViewFactoryOptions = {}) {\n this.factory = new ViewFactory(options)\n\n return this.factory\n }\n\n static factoryInstance () {\n return this.factory\n }\n\n static make (name: ViewName, data: ViewData = {}): ViewInstance {\n return this.factory.make(name, data)\n }\n\n static first (names: ViewName[], data: ViewData = {}): ViewInstance {\n return this.factory.first(names, data)\n }\n\n static exists (name: ViewName) {\n return this.factory.exists(name)\n }\n\n static share (key: string, value: any): typeof View\n static share (data: ViewData): typeof View\n static share (...data: any[]) {\n if (typeof data[0] === 'string') {\n this.factory.share(data[0], data[1])\n } else {\n this.factory.share(data[0] ?? {})\n }\n\n return this\n }\n\n static composer (names: ViewComposerName, composer: ViewComposer): typeof View {\n this.factory.composer(names, composer)\n\n return this\n }\n\n static mount (viewsDirectory: string | URL): typeof View\n static mount (diskName: string, viewsDirectory: string | URL): typeof View\n static mount (diskName: string | URL, viewsDirectory?: string | URL) {\n if (viewsDirectory === undefined) {\n this.factory.mount(diskName)\n } else {\n this.factory.mount(diskName as string, viewsDirectory)\n }\n\n return this\n }\n\n static raw (name: ViewName, contents: string) {\n this.factory.raw(name, contents)\n\n return this\n }\n}\n","import { collectViewData, enterViewData } from './viewContext'\n\nimport { definePlugin as defineClearRouterPlugin } from 'clear-router/core'\n\nexport const clearRouterViewPlugin = defineClearRouterPlugin({\n name: 'arkstack-view',\n setup: ({ useHttpContext }) => {\n useHttpContext((context) => {\n enterViewData(collectViewData(context))\n })\n },\n})"],"mappings":";;;;;;AAGA,MAAM,kBAAkB;AAExB,IAAa,eAAb,MAAa,aAAa;CACtB,MAAwC,EAAE;CAE1C,YAAY,QAAmD;EAC3D,IAAI,QACA,KAAK,MAAM,OAAO;;CAI1B,IAAK,OAAe,SAAyB;EACzC,MAAM,MAAM,SAAS;EACrB,MAAM,WAAW,WAAW,QAAQ;EAEpC,IAAI,CAAC,SAAS,QACV,OAAO;EAGX,KAAK,IAAI,OAAO,CACZ,GAAI,KAAK,IAAI,QAAQ,EAAE,EACvB,GAAG,SACN;EAED,OAAO;;CAGX,MAAO,QAAkD;EACrD,MAAM,WAAW,kBAA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OAAO,SAAS;EAEtC,OAAO;;CAKX,OAAO,MAAO,UAAwB,gBAA+B;EACjE,IAAI,mBAAmB,KAAA,GACnB,KAAK,QAAQ,MAAM,SAAS;OAE5B,KAAK,QAAQ,MAAM,UAAoB,eAAe;EAG1D,OAAO;;CAGX,OAAO,IAAK,MAAgB,UAAkB;EAC1C,KAAK,QAAQ,IAAI,MAAM,SAAS;EAEhC,OAAO;;;;;AC5Ef,MAAa,wBAAwBA,aAAwB;CACzD,MAAM;CACN,QAAQ,EAAE,qBAAqB;EAC3B,gBAAgB,YAAY;GACxB,cAAc,gBAAgB,QAAQ,CAAC;IACzC;;CAET,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { t as clearRouterViewPlugin } from "./plugins-D3vyoc8i.js";
2
+ export { clearRouterViewPlugin };
package/dist/setup.js ADDED
@@ -0,0 +1,8 @@
1
+ import { t as clearRouterViewPlugin } from "./plugins-OaO2BC-T.js";
2
+ import { CoreRouter } from "clear-router/core";
3
+ //#region src/setup.ts
4
+ CoreRouter.use(clearRouterViewPlugin);
5
+ //#endregion
6
+ export { clearRouterViewPlugin };
7
+
8
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","names":[],"sources":["../src/setup.ts"],"sourcesContent":["import { CoreRouter } from 'clear-router/core'\nimport { clearRouterViewPlugin } from './plugins'\n\nvoid CoreRouter.use(clearRouterViewPlugin)\n\nexport { clearRouterViewPlugin }\n"],"mappings":";;;AAGK,WAAW,IAAI,sBAAsB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkstack/view",
3
- "version": "0.7.20",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "description": "View module for Arkstack, providing template rendering and view integration utilities.",
6
6
  "homepage": "https://arkstack.toneflix.net/guide/views",
@@ -16,6 +16,7 @@
16
16
  "exports": {
17
17
  ".": "./dist/index.js",
18
18
  "./MakeViewCommand": "./dist/commands/MakeViewCommand.js",
19
+ "./setup": "./dist/setup.js",
19
20
  "./package.json": "./package.json"
20
21
  },
21
22
  "keywords": [
@@ -35,11 +36,15 @@
35
36
  },
36
37
  "peerDependencies": {
37
38
  "@h3ravel/musket": "^0.10.1",
38
- "@arkstack/common": "^0.7.20"
39
+ "clear-router": "^2.7.7",
40
+ "@arkstack/common": "^0.9.0"
39
41
  },
40
42
  "peerDependenciesMeta": {
41
43
  "@h3ravel/musket": {
42
44
  "optional": true
45
+ },
46
+ "clear-router": {
47
+ "optional": true
43
48
  }
44
49
  },
45
50
  "scripts": {
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["Edge"],"sources":["../src/helpers.ts","../src/packageViews.ts","../src/ViewInstance.ts","../src/ViewFactory.ts","../src/View.ts"],"sourcesContent":["import type { ViewComposer, ViewComposerObject, ViewData, ViewName } from './types'\n\nimport { View } from './View'\nimport { ViewFactory } from './ViewFactory'\nimport { ViewInstance } from './ViewInstance'\n\nexport function view (): ViewFactory\nexport function view (name: ViewName, data?: ViewData): ViewInstance\nexport function view (name?: ViewName, data: ViewData = {}) {\n if (name === undefined) {\n return View.factoryInstance()\n }\n\n return View.make(name, data)\n}\n\nexport const isClass = <T = unknown> (\n target: unknown\n): target is new (...args: any[]) => T => {\n return typeof target === 'function'\n && /^class\\s/.test(Function.prototype.toString.call(target))\n}\n\nexport const mergeData = (target: ViewData, data: any[]) => {\n if (data.length === 0) {\n return target\n }\n\n if (typeof data[0] === 'string') {\n target[data[0]] = data[1]\n\n return target\n }\n\n for (const value of data) {\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n Object.assign(target, value)\n }\n }\n\n return target\n}\n\nexport const runComposerSync = (composer: ViewComposer, view: ViewInstance) => {\n const result = runComposer(composer, view)\n\n if (result && typeof result.then === 'function') {\n throw new Error('Async view composers cannot be used with renderSync.')\n }\n}\n\nexport const runComposer = (composer: ViewComposer, view: ViewInstance) => {\n if (typeof composer === 'function') {\n if (isClass<ViewComposerObject>(composer)) {\n return new composer().compose(view)\n }\n\n return composer(view)\n }\n\n return composer.compose(view)\n}\n","import { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nexport type PackageViewReference = {\n source: string\n packageName: string\n nodePackageName: string\n diskName: string\n viewName: string\n edgeName: string\n}\n\nexport const parsePackageViewName = (name: string): PackageViewReference | null => {\n if (!name.startsWith('~')) {\n return null\n }\n\n const source = name.slice(1)\n const slashIndex = source.indexOf('/')\n const dotIndex = slashIndex === -1\n ? source.indexOf('.')\n : source.indexOf('.', slashIndex)\n\n if (dotIndex <= 0) {\n throw new Error(`Invalid package view name: ${name}`)\n }\n\n const packageName = source.slice(0, dotIndex)\n const viewName = source.slice(dotIndex + 1)\n\n if (!viewName) {\n throw new Error(`Invalid package view name: ${name}`)\n }\n\n const nodePackageName = slashIndex === -1\n ? packageName\n : `@${packageName}`\n const diskName = `package_${packageName.replace(/[^a-zA-Z0-9_-]/g, '_')}`\n\n return {\n source: name,\n packageName,\n nodePackageName,\n diskName,\n viewName,\n edgeName: `${diskName}::${viewName}`,\n }\n}\n\nexport const resolvePackageViewsPath = (\n nodePackageName: string,\n viewPath = 'resources/views',\n) => {\n const packageRoot = resolve(process.cwd(), 'node_modules', nodePackageName)\n const viewsPath = resolve(packageRoot, viewPath)\n\n if (!existsSync(viewsPath)) {\n throw new Error(`Package views directory not found: ${viewsPath}`)\n }\n\n return viewsPath\n}\n","import type { ComposerRunner, SyncComposerRunner, ViewData } from './types'\n\nimport { mergeData } from './helpers'\n\nexport class ViewInstance implements PromiseLike<string> {\n private payload: ViewData\n private composersHaveRun = false\n\n constructor(\n readonly name: string,\n data: ViewData = {},\n private renderer: {\n render: (name: string, data?: ViewData) => Promise<string>\n renderSync: (name: string, data?: ViewData) => string\n },\n private runComposers: ComposerRunner,\n private runComposersSync: SyncComposerRunner,\n private renderName = name,\n ) {\n this.payload = { ...data }\n }\n\n get data () {\n return this.payload\n }\n\n with (key: string, value: any): this\n with (data: ViewData): this\n with (...data: any[]): this {\n mergeData(this.payload, data)\n\n return this\n }\n\n async render () {\n await this.compose()\n\n return await this.renderer.render(this.renderName, this.payload)\n }\n\n renderSync () {\n this.composeSync()\n\n return this.renderer.renderSync(this.renderName, this.payload)\n }\n\n then<TResult1 = string, TResult2 = never> (\n onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null,\n ): PromiseLike<TResult1 | TResult2> {\n return this.render().then(onfulfilled, onrejected)\n }\n\n private async compose () {\n if (this.composersHaveRun) {\n return\n }\n\n this.composersHaveRun = true\n await this.runComposers(this)\n }\n\n private composeSync () {\n if (this.composersHaveRun) {\n return\n }\n\n this.composersHaveRun = true\n this.runComposersSync(this)\n }\n}\n","import type { ViewComposer, ViewComposerName, ViewData, ViewFactoryOptions, ViewName } from './types'\nimport { mergeData, runComposer, runComposerSync } from './helpers'\nimport { parsePackageViewName, resolvePackageViewsPath } from './packageViews'\n\nimport { Edge } from 'edge.js'\nimport { ViewInstance } from './ViewInstance'\nimport { existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nexport class ViewFactory {\n readonly edge: Edge\n private sharedData: ViewData = {}\n private composers = new Map<ViewName, ViewComposer[]>()\n private mountedPackages = new Set<string>()\n private packageViewsPath: string\n\n constructor(options: ViewFactoryOptions = {}) {\n this.edge = options.edge ?? Edge.create({ cache: options.cache })\n this.packageViewsPath = options.packageViewsPath ?? 'resources/views'\n this.mount(options.viewsPath ?? resolve(process.cwd(), 'src', 'resources', 'views'))\n }\n\n make (name: ViewName, data: ViewData = {}) {\n const edgeName = this.resolveName(name)\n\n return new ViewInstance(\n name,\n { ...this.sharedData, ...data },\n this.edge,\n async view => await this.runComposers(name, view),\n view => this.runComposersSync(name, view),\n edgeName,\n )\n }\n\n first (names: ViewName[], data: ViewData = {}) {\n const name = names.find(candidate => this.exists(candidate))\n\n if (!name) {\n throw new Error(`None of the given views exist: ${names.join(', ')}`)\n }\n\n return this.make(name, data)\n }\n\n exists (name: ViewName) {\n const edgeName = this.resolveName(name)\n\n if (this.edge.loader.templates[edgeName]) {\n return true\n }\n\n try {\n return existsSync(this.edge.loader.makePath(edgeName))\n } catch {\n return false\n }\n }\n\n share (key: string, value: any): this\n share (data: ViewData): this\n share (...data: any[]): this {\n mergeData(this.sharedData, data)\n\n return this\n }\n\n composer (names: ViewComposerName, composer: ViewComposer): this {\n for (const name of Array.isArray(names) ? names : [names]) {\n this.composers.set(name, [\n ...(this.composers.get(name) ?? []),\n composer,\n ])\n }\n\n return this\n }\n\n mount (viewsDirectory: string | URL): this\n mount (diskName: string, viewsDirectory: string | URL): this\n mount (diskName: string | URL, viewsDirectory?: string | URL): this {\n if (viewsDirectory === undefined) {\n this.edge.mount(diskName)\n\n return this\n }\n\n this.edge.mount(diskName as string, viewsDirectory)\n\n return this\n }\n\n raw (name: ViewName, contents: string): this {\n this.edge.registerTemplate(name, { template: contents })\n\n return this\n }\n\n flushShared () {\n this.sharedData = {}\n\n return this\n }\n\n flushComposers () {\n this.composers.clear()\n\n return this\n }\n\n private getComposers (name: ViewName) {\n const edgeName = this.resolveName(name)\n\n return [\n ...(this.composers.get('*') ?? []),\n ...(this.composers.get(edgeName) ?? []),\n ...(this.composers.get(name) ?? []),\n ]\n }\n\n private async runComposers (name: ViewName, view: ViewInstance) {\n for (const composer of this.getComposers(name)) {\n await runComposer(composer, view)\n }\n }\n\n private runComposersSync (name: ViewName, view: ViewInstance) {\n for (const composer of this.getComposers(name)) {\n runComposerSync(composer, view)\n }\n }\n\n private resolveName (name: ViewName) {\n const packageView = parsePackageViewName(name)\n\n if (!packageView) {\n return name\n }\n\n if (!this.mountedPackages.has(packageView.diskName)) {\n this.mount(\n packageView.diskName,\n resolvePackageViewsPath(packageView.nodePackageName, this.packageViewsPath),\n )\n this.mountedPackages.add(packageView.diskName)\n }\n\n return packageView.edgeName\n }\n}\n","import type { ViewComposer, ViewComposerName, ViewData, ViewFactoryOptions, ViewName } from './types'\n\nimport { ViewFactory } from './ViewFactory'\nimport type { ViewInstance } from './ViewInstance'\n\nexport class View {\n private static factory = new ViewFactory()\n\n /**\n * Bootstrap the view service\n */\n static boot () {\n Object.defineProperty(globalThis, 'view', {\n value: (name?: ViewName, data: ViewData = {}) => {\n if (name === undefined) {\n return View.factoryInstance()\n }\n\n return View.make(name, data)\n },\n configurable: true,\n writable: true,\n })\n }\n\n static configure (options: ViewFactoryOptions = {}) {\n this.factory = new ViewFactory(options)\n\n return this.factory\n }\n\n static factoryInstance () {\n return this.factory\n }\n\n static make (name: ViewName, data: ViewData = {}): ViewInstance {\n return this.factory.make(name, data)\n }\n\n static first (names: ViewName[], data: ViewData = {}): ViewInstance {\n return this.factory.first(names, data)\n }\n\n static exists (name: ViewName) {\n return this.factory.exists(name)\n }\n\n static share (key: string, value: any): typeof View\n static share (data: ViewData): typeof View\n static share (...data: any[]) {\n if (typeof data[0] === 'string') {\n this.factory.share(data[0], data[1])\n } else {\n this.factory.share(data[0] ?? {})\n }\n\n return this\n }\n\n static composer (names: ViewComposerName, composer: ViewComposer): typeof View {\n this.factory.composer(names, composer)\n\n return this\n }\n\n static mount (viewsDirectory: string | URL): typeof View\n static mount (diskName: string, viewsDirectory: string | URL): typeof View\n static mount (diskName: string | URL, viewsDirectory?: string | URL) {\n if (viewsDirectory === undefined) {\n this.factory.mount(diskName)\n } else {\n this.factory.mount(diskName as string, viewsDirectory)\n }\n\n return this\n }\n\n static raw (name: ViewName, contents: string) {\n this.factory.raw(name, contents)\n\n return this\n }\n}\n"],"mappings":";;;;AAQA,SAAgB,KAAM,MAAiB,OAAiB,EAAE,EAAE;CACxD,IAAI,SAAS,KAAA,GACT,OAAO,KAAK,iBAAiB;CAGjC,OAAO,KAAK,KAAK,MAAM,KAAK;;AAGhC,MAAa,WACT,WACsC;CACtC,OAAO,OAAO,WAAW,cAClB,WAAW,KAAK,SAAS,UAAU,SAAS,KAAK,OAAO,CAAC;;AAGpE,MAAa,aAAa,QAAkB,SA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