@naanlang/naan 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.
- package/LICENSE.md +21 -0
- package/README.md +46 -0
- package/dist/env_web.js +431 -0
- package/dist/naan.min.js +73 -0
- package/frameworks/browser/browser.nlg +30 -0
- package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
- package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
- package/frameworks/browser/sworker.js +192 -0
- package/frameworks/browser/terminals.nlg +787 -0
- package/frameworks/browser/workers.nlg +386 -0
- package/frameworks/client/apiclient.nlg +183 -0
- package/frameworks/client/client.nlg +29 -0
- package/frameworks/client/psm_client.nlg +572 -0
- package/frameworks/common/common.nlg +464 -0
- package/frameworks/common/preferences.nlg +131 -0
- package/frameworks/common/repltools.nlg +100 -0
- package/frameworks/common/watching.nlg +97 -0
- package/frameworks/node/apiserver.nlg +399 -0
- package/frameworks/node/filesystem.nlg +1012 -0
- package/frameworks/node/gitter.nlg +234 -0
- package/frameworks/node/node.nlg +81 -0
- package/frameworks/node/psm_server.nlg +465 -0
- package/frameworks/node/worker.nlg +560 -0
- package/frameworks/project/build.nlg +1229 -0
- package/frameworks/project/jszip.js +30 -0
- package/frameworks/project/jszip.nlg +87 -0
- package/frameworks/project/proj_cliser.nlg +139 -0
- package/frameworks/project/proj_console.nlg +137 -0
- package/frameworks/project/proj_folder.nlg +143 -0
- package/frameworks/project/proj_lambda.nlg +137 -0
- package/frameworks/project/proj_static.nlg +138 -0
- package/frameworks/project/project.nlg +29 -0
- package/frameworks/project/projects.nlg +587 -0
- package/frameworks/project/uglifyjs.js +1 -0
- package/frameworks/project/uglifyjs.nlg +79 -0
- package/frameworks/running/debugcom.nlg +163 -0
- package/frameworks/running/debugnub.nlg +565 -0
- package/frameworks/running/debugutil.nlg +510 -0
- package/frameworks/running/executors.nlg +767 -0
- package/frameworks/running/running.nlg +151 -0
- package/frameworks/running/sourcecode.nlg +346 -0
- package/frameworks/running/taskexec.nlg +196 -0
- package/frameworks/storage/dbt_pouch.nlg +773 -0
- package/frameworks/storage/file_manager.nlg +772 -0
- package/frameworks/storage/psm.nlg +326 -0
- package/frameworks/storage/psm_dbtables.nlg +814 -0
- package/frameworks/storage/resources.nlg +445 -0
- package/frameworks/storage/storage.nlg +52 -0
- package/lib/browser/env_web.js +431 -0
- package/lib/browser/env_webworker.js +146 -0
- package/lib/browser/require.js +1653 -0
- package/lib/core/naanlib.js +73 -0
- package/lib/env_node.js +282 -0
- package/lib/env_nodeworker.js +165 -0
- package/lib/node_repl.js +25 -0
- package/lib/node_repl_init.nlg +52 -0
- package/package.json +13 -0
- package/plugins/gitClient/clientops.nlg +317 -0
- package/plugins/gitClient/gitClient.nlg +63 -0
- package/plugins/gitClient/gitutils.nlg +1331 -0
- package/plugins/gitClient/minimatch.js +945 -0
- package/plugins/gitClient/minimatch_license.txt +15 -0
- package/plugins/gitClient/minimatch_readme.md +208 -0
- package/plugins/nodeLib/nodeLib.nlg +26 -0
- package/plugins/nodeLib/node_cp.nlg +65 -0
- package/plugins/nodeLib/node_fs.nlg +137 -0
- package/plugins/nodeLib/node_https.nlg +172 -0
- package/plugins/nodeLib/node_util.nlg +180 -0
- package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
- package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
- package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
- package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
- package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
- package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
- package/plugins/serviceAws/aws_cognito.nlg +76 -0
- package/plugins/serviceAws/aws_dynamo.nlg +509 -0
- package/plugins/serviceAws/aws_lambda.nlg +95 -0
- package/plugins/serviceAws/aws_s3.nlg +134 -0
- package/plugins/serviceAws/aws_utils.nlg +86 -0
- package/plugins/serviceAws/dbt_aws.nlg +769 -0
- package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
- package/plugins/serviceAws/psm_aws.nlg +258 -0
- package/plugins/serviceAws/serviceAws.nlg +38 -0
- package/plugins/serviceGitHub/gitops.nlg +522 -0
- package/plugins/serviceGitHub/psm_github.nlg +205 -0
- package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
- package/plugins/serviceGitLab/gitops.nlg +528 -0
- package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
- package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
- package/test/harness.nlg +312 -0
- package/test/node_test.js +33 -0
- package/test/test_01_core.nlg +768 -0
- package/test/test_02_context.nlg +269 -0
- package/test/test_03_jsinterop.nlg +137 -0
- package/test/test_04_numerics.nlg +450 -0
- package/test/test_05_strings.nlg +63 -0
- package/test/test_06_lingoparse.nlg +500 -0
- package/test/test_07_lingo.nlg +623 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* psm.nlg
|
|
3
|
+
* frameworks/storage
|
|
4
|
+
*
|
|
5
|
+
* PSM - Project Storage Manager.
|
|
6
|
+
*
|
|
7
|
+
* column positioning: // // !
|
|
8
|
+
*
|
|
9
|
+
* Copyright (c) 2019-2021 by Richard C. Zulch
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* MakePSMutil
|
|
16
|
+
*
|
|
17
|
+
* Filesystem utility object for operations common to all (or most) filesystems. This returns
|
|
18
|
+
* the new object, which is lightweight so this can be used on the fly.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
closure MakePSMutil(fs, local util) {
|
|
23
|
+
util = new(object, this)
|
|
24
|
+
util.fs = fs
|
|
25
|
+
|
|
26
|
+
// uniqueName
|
|
27
|
+
//
|
|
28
|
+
// Create a unique name at the specified path using the provided base name by incrementing
|
|
29
|
+
// suffixes. If copy is specified then that suffix is applied if not already present. The
|
|
30
|
+
// return value the new name.
|
|
31
|
+
|
|
32
|
+
closure uniqueName(path, base, copy, local newname, error, info, current) {
|
|
33
|
+
newname = base
|
|
34
|
+
loop {
|
|
35
|
+
`(error, info) = fs.info(fs.path.join(path, newname))
|
|
36
|
+
if error
|
|
37
|
+
return (newname) // success on error
|
|
38
|
+
if copy {
|
|
39
|
+
current = RegExp("(.+ ".concat(copy, ") ([0-9]*)$")).exec(newname) // <newname> <copy> <number>
|
|
40
|
+
if current
|
|
41
|
+
newname = current.1.concat(" ", toint(current.2)+1)
|
|
42
|
+
else if (current = RegExp("(.+ ".concat(copy, ")$")).exec(newname)) // <newname> <copy>
|
|
43
|
+
newname = current.1.concat(" 2")
|
|
44
|
+
else
|
|
45
|
+
newname = newname.trim().concat(" ", copy) }
|
|
46
|
+
else {
|
|
47
|
+
current = RegExp("(.+) ([0-9]*)$").exec(newname) // <newname> <number>
|
|
48
|
+
if current
|
|
49
|
+
newname = current.1.concat(" ", toint(current.2)+1)
|
|
50
|
+
else
|
|
51
|
+
newname = newname.trim().concat(" 2") }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// treeDirUpdate
|
|
56
|
+
//
|
|
57
|
+
// Update a directory within an existing tree data structure. The result is a standard tuple with
|
|
58
|
+
// (error, changes) where the changes are added/deleted/changed. This assumes that children changed
|
|
59
|
+
// if their info is different
|
|
60
|
+
|
|
61
|
+
util.treeDirUpdate = closure treeDirUpdate(treepath, dirpath, tree, callback, local error, inpath, treedir, files) {
|
|
62
|
+
if !callback
|
|
63
|
+
return (syncAdapter(treeDirUpdate, treepath, dirpath, tree))
|
|
64
|
+
if !dirpath.startsWith(treepath)
|
|
65
|
+
return (callback(Error("treeDirUpdate: dirpath must match treepath", treepath, dirpath)))
|
|
66
|
+
inpath = dirpath.slice(treepath.length) // inpath is now what extends into tree
|
|
67
|
+
treedir = function findir(node, path, local segment, child) {
|
|
68
|
+
segment = path.pop()
|
|
69
|
+
if !segment || segment == ""
|
|
70
|
+
return (node)
|
|
71
|
+
for child in node.children
|
|
72
|
+
if child.name == segment
|
|
73
|
+
return (findir(child, path))
|
|
74
|
+
false
|
|
75
|
+
} (tree, inpath.split(tree.data.pathsep).reverse())
|
|
76
|
+
if !treedir
|
|
77
|
+
return (callback(Error("treeDirUpdate: can't find directory within tree", inpath)))
|
|
78
|
+
`(error, files) = fs.dirList(dirpath, { head: true })
|
|
79
|
+
if error
|
|
80
|
+
return (callback(error))
|
|
81
|
+
//
|
|
82
|
+
// compare new files with existing treedir children
|
|
83
|
+
//
|
|
84
|
+
let (original, updated, odex, udex, added, deleted, changed, newchildren, newchild, dirkids) {
|
|
85
|
+
original = treedir.children
|
|
86
|
+
updated = files.children
|
|
87
|
+
odex = udex = 0
|
|
88
|
+
added = []
|
|
89
|
+
deleted = []
|
|
90
|
+
changed = []
|
|
91
|
+
newchildren = []
|
|
92
|
+
while odex < original.length || udex < updated.length {
|
|
93
|
+
if odex >= original.length || original[odex].name > updated[udex].name
|
|
94
|
+
{ // insert updated into original
|
|
95
|
+
newchild = updated[udex]
|
|
96
|
+
if newchild.info.type == "directory"
|
|
97
|
+
newchild.children = "pending" // convert to tree format
|
|
98
|
+
newchildren.push(newchild)
|
|
99
|
+
added.push(updated[udex++])
|
|
100
|
+
}
|
|
101
|
+
else if udex >= updated.length || original[odex].name < updated[udex].name
|
|
102
|
+
deleted.push(original[odex++]) // remove original
|
|
103
|
+
else {
|
|
104
|
+
dirkids = original[odex].children
|
|
105
|
+
if dirkids {
|
|
106
|
+
if updated[udex].info.type != "directory"
|
|
107
|
+
dirkids = undefined // change original directory -> file
|
|
108
|
+
} else {
|
|
109
|
+
if updated[udex].info.type == "directory"
|
|
110
|
+
dirkids = "pending" // change file -> directory
|
|
111
|
+
}
|
|
112
|
+
if original[odex].info != updated[udex].info
|
|
113
|
+
|| dirkids !== original[odex].children { // info or children, new or changed
|
|
114
|
+
original[odex].children = dirkids
|
|
115
|
+
changed.push(original[odex])
|
|
116
|
+
original[odex].info = updated[udex].info }
|
|
117
|
+
newchildren.push(original[odex])
|
|
118
|
+
++odex
|
|
119
|
+
++udex
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
treedir.children = newchildren
|
|
123
|
+
callback(false, {
|
|
124
|
+
added: added
|
|
125
|
+
deleted: deleted
|
|
126
|
+
changed: changed
|
|
127
|
+
})
|
|
128
|
+
} ()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// treeAddFiles
|
|
132
|
+
//
|
|
133
|
+
// Add an array of files to an existing tree. We cannot be sure of reproducing the exact original
|
|
134
|
+
// collation order, because it was determined by the original creator of the tree, but at least
|
|
135
|
+
// we don't care what it was. This silently omits any additions that have a directory path that
|
|
136
|
+
// conflicts with a file. This does not perform i/o and there is no useful return value.
|
|
137
|
+
|
|
138
|
+
util.treeAddFiles = closure treeAddFiles(files, tree) {
|
|
139
|
+
// Return the node for a directory path, creating as needed
|
|
140
|
+
function find(dirpath) {
|
|
141
|
+
function subfind(node, path, local segment, child) {
|
|
142
|
+
segment = path.pop()
|
|
143
|
+
if !segment || segment == ""
|
|
144
|
+
return (node) // found the node
|
|
145
|
+
for child in node.children
|
|
146
|
+
if child.name == segment
|
|
147
|
+
return (subfind(child, path))
|
|
148
|
+
child = { // need new directory
|
|
149
|
+
name: segment
|
|
150
|
+
chidren: []
|
|
151
|
+
}
|
|
152
|
+
if !node.children
|
|
153
|
+
return (false) // file in the way
|
|
154
|
+
else if !array(node.children)
|
|
155
|
+
node.children = [child] // enumeration was pending, etc.
|
|
156
|
+
else
|
|
157
|
+
node.children.push(child) // node.children left unsorted
|
|
158
|
+
return (subfind(child, path))
|
|
159
|
+
} (tree, dirpath.split(tree.data.pathsep).reverse())
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// addPaths
|
|
163
|
+
//
|
|
164
|
+
// Add an array of paths to the directories in the trees.
|
|
165
|
+
function addPaths(files, local filepath, sepdex, dirpath, filename, dirnode, dirnodepath) {
|
|
166
|
+
// sort files to increasing order
|
|
167
|
+
for filepath in files { // create dirdex array of directories and their children
|
|
168
|
+
sepdex = filepath.lastIndexOf(tree.data.pathsep)
|
|
169
|
+
if sepdex < 0 {
|
|
170
|
+
dirpath = ""
|
|
171
|
+
filename = filepath }
|
|
172
|
+
else {
|
|
173
|
+
dirpath = filepath.slice(0, sepdex)
|
|
174
|
+
filename = filepath.slice(sepdex+1) }
|
|
175
|
+
if !dirnode || dirnodepath != dirpath {
|
|
176
|
+
dirnode = find(dirpath)
|
|
177
|
+
dirnodepath = dirpath }
|
|
178
|
+
if !dirnode {
|
|
179
|
+
debuglog("treeAddFiles: cannot add", filepath)
|
|
180
|
+
continue // can't add this file
|
|
181
|
+
}
|
|
182
|
+
dirnode.children = dirnode.children.concat({
|
|
183
|
+
name: filename
|
|
184
|
+
deleted: "yes"
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
} (files)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// newFolder
|
|
191
|
+
//
|
|
192
|
+
// Create a new folder with auto-naming to be unique at the path. The result is a standard
|
|
193
|
+
// (error, newname) tuple.
|
|
194
|
+
|
|
195
|
+
util.newFolder = closure newFolder(path, name, callback) {
|
|
196
|
+
if !callback
|
|
197
|
+
return (syncAdapter(newFolder, path, name))
|
|
198
|
+
if !name
|
|
199
|
+
name = "untitled folder"
|
|
200
|
+
fs.mkdir(fs.path.join(path, uniqueName(path, name)), callback)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// newFile
|
|
204
|
+
//
|
|
205
|
+
// Create a new file with auto-naming to be unique at the path. The result is a standard
|
|
206
|
+
// (error, newname) tuple.
|
|
207
|
+
|
|
208
|
+
util.newFile = closure newFile(path, name, callback) {
|
|
209
|
+
if !callback
|
|
210
|
+
return (syncAdapter(newFile, path, name))
|
|
211
|
+
if !name
|
|
212
|
+
name = "file"
|
|
213
|
+
fs.writeFile(fs.path.join(path, uniqueName(path, name)), "", false, callback)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// duplicate
|
|
217
|
+
//
|
|
218
|
+
// Duplicate a file or folder with auto-naming to be unique in the directory. The result is a
|
|
219
|
+
// standard (error, newname) tuple.
|
|
220
|
+
|
|
221
|
+
util.duplicate = closure duplicate(path, name, copy, callback, local srcpath, newname) {
|
|
222
|
+
if !callback
|
|
223
|
+
return (syncAdapter(duplicate, path, name, copy))
|
|
224
|
+
if name
|
|
225
|
+
srcpath = fs.path.join(path, name)
|
|
226
|
+
else {
|
|
227
|
+
srcpath = path
|
|
228
|
+
name = fs.path.basename(path)
|
|
229
|
+
path = fs.path.dirname(path)
|
|
230
|
+
}
|
|
231
|
+
if !copy
|
|
232
|
+
copy = "copy"
|
|
233
|
+
newname = uniqueName(path, name, copy)
|
|
234
|
+
fs.copy(srcpath, newname, false, callback)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// deepcopy
|
|
238
|
+
//
|
|
239
|
+
// Perform a deep copy of an array of sources from the current filesystem and specified inpath to
|
|
240
|
+
// the outfs filesystem and specified outpath. The input path is used to find the source files,
|
|
241
|
+
// however it is not added to the output. The result is a standard error tuple, where the errors
|
|
242
|
+
// are an array if any occur.
|
|
243
|
+
|
|
244
|
+
util.deepcopy = closure deepcopy(inpath, sources, outfs, outpath, options, callback, local errors, copies) {
|
|
245
|
+
if !callback
|
|
246
|
+
return (syncAdapter(deepcopy, inpath, sources, outfs, outpath, options))
|
|
247
|
+
if !array(sources) || !string(inpath) || !string(outpath)
|
|
248
|
+
return (callback(Error("deepcopy: invalid arguments")))
|
|
249
|
+
errors = []
|
|
250
|
+
copies = []
|
|
251
|
+
sources = new(sources) // don't modify the original!
|
|
252
|
+
asyncArray(sources, 10, closure mklist(entry, index, elements, local srcpath, destpath, error, folder, node) {
|
|
253
|
+
srcpath = fs.path.join(inpath, entry)
|
|
254
|
+
`(error, folder) = fs.dirList(srcpath)
|
|
255
|
+
if error && error.code != "ENOTDIR"
|
|
256
|
+
return (errors.push(error))
|
|
257
|
+
destpath = outfs.path.join(outpath, entry) // "." if both empty strings
|
|
258
|
+
if !error {
|
|
259
|
+
if destpath != "."
|
|
260
|
+
`(error, node) = outfs.mkdir(destpath) // may already exist but we don't care
|
|
261
|
+
if error
|
|
262
|
+
return (errors.push(error)) // don't do children if we can't form destination
|
|
263
|
+
for node in folder.children
|
|
264
|
+
sources.push(fs.path.join(entry, node.name)) // omit inpath from sources
|
|
265
|
+
}
|
|
266
|
+
else
|
|
267
|
+
copies.push({ // copy the file
|
|
268
|
+
source: srcpath
|
|
269
|
+
dest: destpath
|
|
270
|
+
})
|
|
271
|
+
}).wait()
|
|
272
|
+
asyncArray(copies, 10, closure cpfiles(entry, index, elements, local error, data, instat, outstat) {
|
|
273
|
+
`(error, instat) = fs.info(entry.source)
|
|
274
|
+
if !error {
|
|
275
|
+
`(error, outstat) = outfs.info(entry.dest)
|
|
276
|
+
if !error && (instat.md5 && instat.md5 == outstat.md5 || instat.mtimeMs <= outstat.mtimeMs)
|
|
277
|
+
return // file unchanged
|
|
278
|
+
`(error, data) = fs.readFile(entry.source, { encoding: "binary"})
|
|
279
|
+
if !error
|
|
280
|
+
`(error, data) = outfs.writeFile(entry.dest, data, { encoding: "binary"})
|
|
281
|
+
}
|
|
282
|
+
if error
|
|
283
|
+
errors.push(error)
|
|
284
|
+
}).wait()
|
|
285
|
+
if errors.length > 0
|
|
286
|
+
callback(errors)
|
|
287
|
+
else
|
|
288
|
+
callback(false, { ok: true })
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// finis
|
|
292
|
+
util
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
/*
|
|
297
|
+
* MakePSM
|
|
298
|
+
*
|
|
299
|
+
* Create a new PSM manager.
|
|
300
|
+
*
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
closure MakePSM(dbname, local psm) {
|
|
304
|
+
ResourceManager(dbname, "PSM_locations/")
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
/*
|
|
309
|
+
* psmInit
|
|
310
|
+
*
|
|
311
|
+
* Initialize the psm component.
|
|
312
|
+
*
|
|
313
|
+
*/
|
|
314
|
+
|
|
315
|
+
function psmInit(local manifest) {
|
|
316
|
+
|
|
317
|
+
manifest = `(MakePSMutil, MakePSM, psmInit)
|
|
318
|
+
|
|
319
|
+
Naan.module.build(module.id, "psm", function(modobj, compobj) {
|
|
320
|
+
require("./storage.nlg")
|
|
321
|
+
require("./resources.nlg")
|
|
322
|
+
compobj.manifest = manifest
|
|
323
|
+
modobj.exports.MakePSM = MakePSM
|
|
324
|
+
modobj.exports.MakePSMutil = MakePSMutil
|
|
325
|
+
})
|
|
326
|
+
} ();
|