structured-fw 0.7.2
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/Config.ts +47 -0
- package/LICENSE +21 -0
- package/README.md +332 -0
- package/app/Types.ts +1 -0
- package/app/models/README.md +9 -0
- package/app/routes/README.md +19 -0
- package/app/views/README.md +1 -0
- package/app/views/layout.html +1 -0
- package/bin/structured +114 -0
- package/build/Config.d.ts +2 -0
- package/build/Config.js +31 -0
- package/build/app/Types.d.ts +1 -0
- package/build/app/Types.js +1 -0
- package/build/app/models/Users.d.ts +0 -0
- package/build/app/models/Users.js +1 -0
- package/build/app/routes/Auth.d.ts +0 -0
- package/build/app/routes/Auth.js +1 -0
- package/build/app/routes/Test.d.ts +2 -0
- package/build/app/routes/Test.js +101 -0
- package/build/app/routes/Todo.d.ts +0 -0
- package/build/app/routes/Todo.js +1 -0
- package/build/app/routes/Upload.d.ts +0 -0
- package/build/app/routes/Upload.js +1 -0
- package/build/app/routes/Validation.d.ts +2 -0
- package/build/app/routes/Validation.js +34 -0
- package/build/app/views/components/ClientImport/ClientImport.client.d.ts +2 -0
- package/build/app/views/components/ClientImport/ClientImport.client.js +4 -0
- package/build/app/views/components/ClientImport/Export.d.ts +1 -0
- package/build/app/views/components/ClientImport/Export.js +1 -0
- package/build/app/views/components/Conditionals/Conditionals.client.d.ts +2 -0
- package/build/app/views/components/Conditionals/Conditionals.client.js +43 -0
- package/build/app/views/components/FormTest/FormTestNested/FormTestNested.d.ts +8 -0
- package/build/app/views/components/FormTest/FormTestNested/FormTestNested.js +7 -0
- package/build/app/views/components/ModelsTest/ModelsTest.client.d.ts +2 -0
- package/build/app/views/components/ModelsTest/ModelsTest.client.js +5 -0
- package/build/app/views/components/MultipartForm/MultipartForm.client.d.ts +0 -0
- package/build/app/views/components/MultipartForm/MultipartForm.client.js +1 -0
- package/build/app/views/components/PassObject/PassObject.d.ts +10 -0
- package/build/app/views/components/PassObject/PassObject.js +10 -0
- package/build/app/views/components/PassObject/ReceiveObj/ReceiveObj.d.ts +6 -0
- package/build/app/views/components/PassObject/ReceiveObj/ReceiveObj.js +6 -0
- package/build/app/views/components/RedrawAbort/RedrawAbort.client.d.ts +2 -0
- package/build/app/views/components/RedrawAbort/RedrawAbort.client.js +6 -0
- package/build/app/views/components/RedrawAbort/RedrawAbort.d.ts +8 -0
- package/build/app/views/components/RedrawAbort/RedrawAbort.js +8 -0
- package/build/app/views/components/ServerSideContext/ServerSideContext.d.ts +7 -0
- package/build/app/views/components/ServerSideContext/ServerSideContext.js +10 -0
- package/build/assets/ts/Export.d.ts +1 -0
- package/build/assets/ts/Export.js +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -0
- package/build/system/Helpers.d.ts +3 -0
- package/build/system/Helpers.js +72 -0
- package/build/system/Symbols.d.ts +3 -0
- package/build/system/Symbols.js +3 -0
- package/build/system/Types.d.ts +171 -0
- package/build/system/Types.js +1 -0
- package/build/system/Util.d.ts +20 -0
- package/build/system/Util.js +336 -0
- package/build/system/client/App.d.ts +7 -0
- package/build/system/client/App.js +8 -0
- package/build/system/client/Client.d.ts +6 -0
- package/build/system/client/Client.js +9 -0
- package/build/system/client/ClientComponent.d.ts +68 -0
- package/build/system/client/ClientComponent.js +734 -0
- package/build/system/client/DataStore.d.ts +22 -0
- package/build/system/client/DataStore.js +64 -0
- package/build/system/client/DataStoreView.d.ts +19 -0
- package/build/system/client/DataStoreView.js +56 -0
- package/build/system/client/EventEmitter.d.ts +7 -0
- package/build/system/client/EventEmitter.js +31 -0
- package/build/system/client/Net.d.ts +13 -0
- package/build/system/client/Net.js +39 -0
- package/build/system/client/NetRequest.d.ts +13 -0
- package/build/system/client/NetRequest.js +45 -0
- package/build/system/server/Application.d.ts +31 -0
- package/build/system/server/Application.js +171 -0
- package/build/system/server/Component.d.ts +27 -0
- package/build/system/server/Component.js +249 -0
- package/build/system/server/Components.d.ts +12 -0
- package/build/system/server/Components.js +77 -0
- package/build/system/server/Cookies.d.ts +6 -0
- package/build/system/server/Cookies.js +19 -0
- package/build/system/server/Document.d.ts +24 -0
- package/build/system/server/Document.js +107 -0
- package/build/system/server/DocumentHead.d.ts +32 -0
- package/build/system/server/DocumentHead.js +118 -0
- package/build/system/server/FormValidation.d.ts +16 -0
- package/build/system/server/FormValidation.js +197 -0
- package/build/system/server/Handlebars.d.ts +11 -0
- package/build/system/server/Handlebars.js +34 -0
- package/build/system/server/Request.d.ts +21 -0
- package/build/system/server/Request.js +356 -0
- package/build/system/server/Session.d.ts +23 -0
- package/build/system/server/Session.js +114 -0
- package/build/system/server/dom/DOMFragment.d.ts +4 -0
- package/build/system/server/dom/DOMFragment.js +6 -0
- package/build/system/server/dom/DOMNode.d.ts +31 -0
- package/build/system/server/dom/DOMNode.js +110 -0
- package/build/system/server/dom/HTMLParser.d.ts +21 -0
- package/build/system/server/dom/HTMLParser.js +204 -0
- package/index.ts +4 -0
- package/package.json +31 -0
- package/system/Helpers.ts +97 -0
- package/system/Symbols.ts +6 -0
- package/system/Types.ts +234 -0
- package/system/Util.ts +488 -0
- package/system/client/App.ts +11 -0
- package/system/client/Client.ts +9 -0
- package/system/client/ClientComponent.ts +1117 -0
- package/system/client/DataStore.ts +101 -0
- package/system/client/DataStoreView.ts +82 -0
- package/system/client/EventEmitter.ts +38 -0
- package/system/client/Net.ts +58 -0
- package/system/client/NetRequest.ts +64 -0
- package/system/server/Application.ts +230 -0
- package/system/server/Component.ts +404 -0
- package/system/server/Components.ts +111 -0
- package/system/server/Cookies.ts +29 -0
- package/system/server/Document.ts +163 -0
- package/system/server/DocumentHead.ts +150 -0
- package/system/server/FormValidation.ts +231 -0
- package/system/server/Handlebars.ts +51 -0
- package/system/server/Request.ts +497 -0
- package/system/server/Session.ts +151 -0
- package/system/server/dom/DOMFragment.ts +7 -0
- package/system/server/dom/DOMNode.ts +140 -0
- package/system/server/dom/HTMLParser.ts +238 -0
- package/tsconfig.json +35 -0
package/system/Types.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { Application } from "./server/Application.js";
|
|
3
|
+
import { symbolArrays } from "./Symbols.js";
|
|
4
|
+
import { RequestContextData } from "../app/Types.js";
|
|
5
|
+
import { Net } from './client/Net.js';
|
|
6
|
+
import { ClientComponent } from './client/ClientComponent.js';
|
|
7
|
+
import { Component } from "./server/Component.js";
|
|
8
|
+
|
|
9
|
+
export type StructuredConfig = {
|
|
10
|
+
readonly envPrefix?: string,
|
|
11
|
+
readonly autoInit: boolean,
|
|
12
|
+
url: {
|
|
13
|
+
removeTrailingSlash: boolean,
|
|
14
|
+
componentRender: false | string,
|
|
15
|
+
isAsset: (url: string) => boolean
|
|
16
|
+
},
|
|
17
|
+
routes: {
|
|
18
|
+
readonly path: string
|
|
19
|
+
},
|
|
20
|
+
components: {
|
|
21
|
+
readonly path: string,
|
|
22
|
+
readonly componentNameAttribute: string
|
|
23
|
+
},
|
|
24
|
+
session: {
|
|
25
|
+
readonly cookieName: string,
|
|
26
|
+
readonly keyLength: number,
|
|
27
|
+
readonly durationSeconds: number,
|
|
28
|
+
readonly garbageCollectIntervalSeconds: number,
|
|
29
|
+
readonly garbageCollectAfterSeconds: number
|
|
30
|
+
},
|
|
31
|
+
http: {
|
|
32
|
+
host?: string,
|
|
33
|
+
port: number,
|
|
34
|
+
linkHeaderRel: 'preload' | 'preconnect'
|
|
35
|
+
},
|
|
36
|
+
readonly runtime: 'Node.js' | 'Deno'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type StructuredClientConfig = {
|
|
40
|
+
componentRender: StructuredConfig['url']['componentRender'],
|
|
41
|
+
componentNameAttribute: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type RequestMethod = 'GET'|'POST'|'PUT'|'PATCH'|'DELETE';
|
|
45
|
+
|
|
46
|
+
export type RequestCallback = (ctx: RequestContext) => Promise<any>
|
|
47
|
+
|
|
48
|
+
export type RequestHandler = {
|
|
49
|
+
match: Array<URISegmentPattern>|RegExp,
|
|
50
|
+
methods: Array<RequestMethod>,
|
|
51
|
+
callback: RequestCallback,
|
|
52
|
+
scope: any,
|
|
53
|
+
|
|
54
|
+
// if true, no (before/after)RequestHandler event is emitted, body and GET args not parsed
|
|
55
|
+
staticAsset: boolean
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type RequestContext = {
|
|
59
|
+
request: IncomingMessage,
|
|
60
|
+
response: ServerResponse,
|
|
61
|
+
args: URIArguments,
|
|
62
|
+
handler: null|RequestHandler,
|
|
63
|
+
|
|
64
|
+
cookies: Record<string, string>,
|
|
65
|
+
|
|
66
|
+
// POSTed data, parsed to object
|
|
67
|
+
body?: PostedDataDecoded,
|
|
68
|
+
|
|
69
|
+
bodyRaw?: Buffer,
|
|
70
|
+
|
|
71
|
+
// files extracted from request body
|
|
72
|
+
// currently only multipart/form-data
|
|
73
|
+
files?: Record<string, RequestBodyRecordValue>,
|
|
74
|
+
|
|
75
|
+
// user defined data
|
|
76
|
+
data: RequestContextData,
|
|
77
|
+
|
|
78
|
+
// if session is started and user has visited any page
|
|
79
|
+
sessionId?: string,
|
|
80
|
+
|
|
81
|
+
// true if x-requested-with header is received and it equals 'xmlhttprequest'
|
|
82
|
+
isAjax: boolean,
|
|
83
|
+
|
|
84
|
+
getArgs: PostedDataDecoded,
|
|
85
|
+
|
|
86
|
+
respondWith: (data: any) => void,
|
|
87
|
+
redirect: (to: string, statusCode?: number) => void,
|
|
88
|
+
show404: () => Promise<void>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type PostedDataDecoded = Record<string, string | boolean | Array<string | boolean | PostedDataDecoded> | Record<string, string | boolean | Array<string | boolean | PostedDataDecoded>> | Record<string, string | boolean | Array<string | boolean>>>
|
|
92
|
+
|
|
93
|
+
export type RequestBodyRecordValue = string | Array<RequestBodyRecordValue> | { [key: string]: RequestBodyRecordValue } | { [key: string]: RequestBodyFile } | Array<RequestBodyFile> | RequestBodyFile;
|
|
94
|
+
|
|
95
|
+
export interface RequestBodyArguments {
|
|
96
|
+
[key: string] : RequestBodyRecordValue,
|
|
97
|
+
[symbolArrays]? : {
|
|
98
|
+
[key: string] : Array<string>
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type RequestBodyFiles = {
|
|
103
|
+
[key: string] : RequestBodyFile
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type RequestBodyFile = {
|
|
107
|
+
fileName: string,
|
|
108
|
+
data: Buffer,
|
|
109
|
+
type: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type URISegmentPattern = {
|
|
113
|
+
pattern: string|RegExp,
|
|
114
|
+
name?: string,
|
|
115
|
+
type?: 'string'|'number'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export type URIArguments = {
|
|
119
|
+
[key: string] : string|number|RegExpExecArray
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type DocumentResource = {
|
|
123
|
+
path: string,
|
|
124
|
+
attributes: Record<string, string | null>,
|
|
125
|
+
priority: number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type ComponentEntry = {
|
|
129
|
+
name: string,
|
|
130
|
+
path: {
|
|
131
|
+
absolute: string,
|
|
132
|
+
relative: string,
|
|
133
|
+
relativeToViews: string,
|
|
134
|
+
build: string,
|
|
135
|
+
html: string,
|
|
136
|
+
jsServer?: string,
|
|
137
|
+
jsClient?: string
|
|
138
|
+
},
|
|
139
|
+
hasJS: boolean,
|
|
140
|
+
html : string,
|
|
141
|
+
|
|
142
|
+
static: boolean,
|
|
143
|
+
|
|
144
|
+
// server side component module
|
|
145
|
+
module?: ComponentScaffold,
|
|
146
|
+
|
|
147
|
+
// default is "div"
|
|
148
|
+
renderTagName?: string,
|
|
149
|
+
|
|
150
|
+
// if true, all component data is exported to ClientComponent
|
|
151
|
+
exportData: boolean,
|
|
152
|
+
|
|
153
|
+
// selectively export data to ClientComponent
|
|
154
|
+
exportFields? : Array<string>,
|
|
155
|
+
|
|
156
|
+
// attributes added to rendered DOM node
|
|
157
|
+
attributes?: Record<string, string>,
|
|
158
|
+
|
|
159
|
+
// client side component initializer
|
|
160
|
+
initializer?: InitializerFunction
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface ComponentScaffold {
|
|
164
|
+
// rendered tag name (default is "div")
|
|
165
|
+
tagName?: string,
|
|
166
|
+
|
|
167
|
+
exportData?: boolean,
|
|
168
|
+
// selectively export data
|
|
169
|
+
exportFields? : Array<string>,
|
|
170
|
+
|
|
171
|
+
static?: boolean,
|
|
172
|
+
deferred?: (data: Record<string, any>, ctx: RequestContext | undefined, app: Application) => boolean,
|
|
173
|
+
|
|
174
|
+
attributes?: Record<string, string>,
|
|
175
|
+
|
|
176
|
+
getData: (this: ComponentScaffold, data: RequestBodyArguments|LooseObject, ctx: undefined|RequestContext, app: Application, component: Component) => Promise<LooseObject | null>
|
|
177
|
+
[key: string] : any
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type LooseObject = Record<string, any>
|
|
181
|
+
|
|
182
|
+
export type ApplicationEvents = 'serverStarted'|'beforeRequestHandler'|'afterRequestHandler'|'beforeRoutes'|'afterRoutes'|'beforeComponentLoad'|'afterComponentLoad'|'documentCreated'|'beforeAssetAccess'|'afterAssetAccess'|'pageNotFound';
|
|
183
|
+
|
|
184
|
+
export type SessionEntry = {
|
|
185
|
+
sessionId : string,
|
|
186
|
+
lastRequest: number,
|
|
187
|
+
data: LooseObject
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export type ValidationRuleWithArguments = [string, any];
|
|
191
|
+
export type FormValidationEntry = {
|
|
192
|
+
// field_name, human readable name
|
|
193
|
+
field: [string, string],
|
|
194
|
+
rules: Array<string|ValidationRuleWithArguments|ValidatorFunction>
|
|
195
|
+
}
|
|
196
|
+
export type ValidatorFunction = (data: PostedDataDecoded, field: string, arg: number, rules: Array<string|ValidationRuleWithArguments|ValidatorFunction>) => Promise<boolean>;
|
|
197
|
+
export type ValidatorErrorDecorator = (fieldHumanReadable: string, data: PostedDataDecoded, field: string, arg: any) => string | Promise<string>;
|
|
198
|
+
export type ValidationErrors = {
|
|
199
|
+
[field: string] : Array<string>
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type ValidationErrorsSingle = {
|
|
203
|
+
[field: string] : string
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export type ValidationResult = {
|
|
207
|
+
valid: boolean,
|
|
208
|
+
errors: ValidationErrors|ValidationErrorsSingle
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export type InitializerFunction = (this: ClientComponent, ctx : InitializerFunctionContext) => Promise<void>
|
|
212
|
+
|
|
213
|
+
export type Initializers = {
|
|
214
|
+
[key: string] : InitializerFunction
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type InitializerFunctionContext = {
|
|
218
|
+
net: Net,
|
|
219
|
+
isRedraw: boolean
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export type StoreChangeCallback = (key: string, value: any, oldValue: any, componentId: string) => void
|
|
223
|
+
|
|
224
|
+
export type AsteriskAny = '*';
|
|
225
|
+
|
|
226
|
+
export type ClientComponentTransition = {
|
|
227
|
+
fade: false|number,
|
|
228
|
+
slide: false|number
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type ClientComponentTransitionEvent = 'show' | 'hide';
|
|
232
|
+
export type ClientComponentTransitions = Record<ClientComponentTransitionEvent, ClientComponentTransition>;
|
|
233
|
+
|
|
234
|
+
export type EventEmitterCallback = (payload: any) => void
|