libretto 0.1.5 → 0.2.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.
Files changed (183) hide show
  1. package/README.md +213 -17
  2. package/bin/libretto.mjs +18 -0
  3. package/dist/cli/cli.js +201 -0
  4. package/dist/cli/commands/ai.js +21 -0
  5. package/dist/cli/commands/browser.js +56 -0
  6. package/dist/cli/commands/execution.js +407 -0
  7. package/dist/cli/commands/logs.js +65 -0
  8. package/dist/cli/commands/snapshot.js +99 -0
  9. package/dist/cli/core/ai-config.js +149 -0
  10. package/dist/cli/core/browser.js +687 -0
  11. package/dist/cli/core/context.js +113 -0
  12. package/dist/cli/core/pause-signals.js +29 -0
  13. package/dist/cli/core/session.js +183 -0
  14. package/dist/cli/core/snapshot-analyzer.js +492 -0
  15. package/dist/cli/core/telemetry.js +350 -0
  16. package/dist/cli/index.js +13 -0
  17. package/dist/cli/workers/run-integration-runtime.js +204 -0
  18. package/dist/cli/workers/run-integration-worker-protocol.js +0 -0
  19. package/dist/cli/workers/run-integration-worker.js +83 -0
  20. package/dist/index.cjs +127 -0
  21. package/dist/index.d.cts +22 -0
  22. package/dist/index.d.ts +22 -0
  23. package/dist/index.js +110 -0
  24. package/dist/runtime/download/download.cjs +70 -0
  25. package/dist/runtime/download/download.d.cts +35 -0
  26. package/dist/runtime/download/download.d.ts +35 -0
  27. package/dist/runtime/download/download.js +45 -0
  28. package/dist/runtime/download/index.cjs +30 -0
  29. package/dist/runtime/download/index.d.cts +3 -0
  30. package/dist/runtime/download/index.d.ts +3 -0
  31. package/dist/runtime/download/index.js +8 -0
  32. package/dist/runtime/extract/extract.cjs +87 -0
  33. package/dist/runtime/extract/extract.d.cts +23 -0
  34. package/dist/runtime/extract/extract.d.ts +23 -0
  35. package/dist/runtime/extract/extract.js +63 -0
  36. package/dist/runtime/extract/index.cjs +28 -0
  37. package/dist/runtime/extract/index.d.cts +5 -0
  38. package/dist/runtime/extract/index.d.ts +5 -0
  39. package/dist/runtime/extract/index.js +4 -0
  40. package/dist/runtime/network/index.cjs +28 -0
  41. package/dist/runtime/network/index.d.cts +4 -0
  42. package/dist/runtime/network/index.d.ts +4 -0
  43. package/dist/runtime/network/index.js +6 -0
  44. package/dist/runtime/network/network.cjs +91 -0
  45. package/dist/runtime/network/network.d.cts +28 -0
  46. package/dist/runtime/network/network.d.ts +28 -0
  47. package/dist/runtime/network/network.js +67 -0
  48. package/dist/runtime/recovery/agent.cjs +218 -0
  49. package/dist/runtime/recovery/agent.d.cts +13 -0
  50. package/dist/runtime/recovery/agent.d.ts +13 -0
  51. package/dist/runtime/recovery/agent.js +194 -0
  52. package/dist/runtime/recovery/errors.cjs +122 -0
  53. package/dist/runtime/recovery/errors.d.cts +31 -0
  54. package/dist/runtime/recovery/errors.d.ts +31 -0
  55. package/dist/runtime/recovery/errors.js +98 -0
  56. package/dist/runtime/recovery/index.cjs +34 -0
  57. package/dist/runtime/recovery/index.d.cts +7 -0
  58. package/dist/runtime/recovery/index.d.ts +7 -0
  59. package/dist/runtime/recovery/index.js +10 -0
  60. package/dist/runtime/recovery/recovery.cjs +53 -0
  61. package/dist/runtime/recovery/recovery.d.cts +12 -0
  62. package/dist/runtime/recovery/recovery.d.ts +12 -0
  63. package/dist/runtime/recovery/recovery.js +29 -0
  64. package/dist/runtime/step/index.cjs +31 -0
  65. package/dist/runtime/step/index.d.cts +7 -0
  66. package/dist/runtime/step/index.d.ts +7 -0
  67. package/dist/runtime/step/index.js +6 -0
  68. package/dist/runtime/step/runner.cjs +208 -0
  69. package/dist/runtime/step/runner.d.cts +16 -0
  70. package/dist/runtime/step/runner.d.ts +16 -0
  71. package/dist/runtime/step/runner.js +187 -0
  72. package/dist/runtime/step/step.cjs +67 -0
  73. package/dist/runtime/step/step.d.cts +23 -0
  74. package/dist/runtime/step/step.d.ts +23 -0
  75. package/dist/runtime/step/step.js +43 -0
  76. package/dist/runtime/step/types.cjs +16 -0
  77. package/dist/runtime/step/types.d.cts +72 -0
  78. package/dist/runtime/step/types.d.ts +72 -0
  79. package/dist/runtime/step/types.js +0 -0
  80. package/dist/shared/config/config.cjs +44 -0
  81. package/dist/shared/config/config.d.cts +10 -0
  82. package/dist/shared/config/config.d.ts +10 -0
  83. package/dist/shared/config/config.js +18 -0
  84. package/dist/shared/config/index.cjs +32 -0
  85. package/dist/shared/config/index.d.cts +1 -0
  86. package/dist/shared/config/index.d.ts +1 -0
  87. package/dist/shared/config/index.js +10 -0
  88. package/dist/shared/debug/index.cjs +32 -0
  89. package/dist/shared/debug/index.d.cts +2 -0
  90. package/dist/shared/debug/index.d.ts +2 -0
  91. package/dist/shared/debug/index.js +10 -0
  92. package/dist/shared/debug/pause.cjs +56 -0
  93. package/dist/shared/debug/pause.d.cts +23 -0
  94. package/dist/shared/debug/pause.d.ts +23 -0
  95. package/dist/shared/debug/pause.js +30 -0
  96. package/dist/shared/instrumentation/errors.cjs +81 -0
  97. package/dist/shared/instrumentation/errors.d.cts +12 -0
  98. package/dist/shared/instrumentation/errors.d.ts +12 -0
  99. package/dist/shared/instrumentation/errors.js +57 -0
  100. package/dist/shared/instrumentation/index.cjs +35 -0
  101. package/dist/shared/instrumentation/index.d.cts +6 -0
  102. package/dist/shared/instrumentation/index.d.ts +6 -0
  103. package/dist/shared/instrumentation/index.js +12 -0
  104. package/dist/shared/instrumentation/instrument.cjs +206 -0
  105. package/dist/shared/instrumentation/instrument.d.cts +32 -0
  106. package/dist/shared/instrumentation/instrument.d.ts +32 -0
  107. package/dist/shared/instrumentation/instrument.js +190 -0
  108. package/dist/shared/llm/client.cjs +139 -0
  109. package/dist/shared/llm/client.d.cts +6 -0
  110. package/dist/shared/llm/client.d.ts +6 -0
  111. package/dist/shared/llm/client.js +115 -0
  112. package/dist/shared/llm/index.cjs +28 -0
  113. package/dist/shared/llm/index.d.cts +3 -0
  114. package/dist/shared/llm/index.d.ts +3 -0
  115. package/dist/shared/llm/index.js +4 -0
  116. package/dist/shared/llm/types.cjs +16 -0
  117. package/dist/shared/llm/types.d.cts +34 -0
  118. package/dist/shared/llm/types.d.ts +34 -0
  119. package/dist/shared/llm/types.js +0 -0
  120. package/dist/shared/logger/index.cjs +35 -0
  121. package/dist/shared/logger/index.d.cts +2 -0
  122. package/dist/shared/logger/index.d.ts +2 -0
  123. package/dist/shared/logger/index.js +12 -0
  124. package/dist/shared/logger/logger.cjs +200 -0
  125. package/dist/shared/logger/logger.d.cts +70 -0
  126. package/dist/shared/logger/logger.d.ts +70 -0
  127. package/dist/shared/logger/logger.js +176 -0
  128. package/dist/shared/logger/sinks.cjs +160 -0
  129. package/dist/shared/logger/sinks.d.cts +9 -0
  130. package/dist/shared/logger/sinks.d.ts +9 -0
  131. package/dist/shared/logger/sinks.js +124 -0
  132. package/dist/shared/paths/paths.cjs +104 -0
  133. package/dist/shared/paths/paths.d.cts +10 -0
  134. package/dist/shared/paths/paths.d.ts +10 -0
  135. package/dist/shared/paths/paths.js +73 -0
  136. package/dist/shared/run/api.cjs +35 -0
  137. package/dist/shared/run/api.d.cts +3 -0
  138. package/dist/shared/run/api.d.ts +3 -0
  139. package/dist/shared/run/api.js +12 -0
  140. package/dist/shared/run/browser.cjs +98 -0
  141. package/dist/shared/run/browser.d.cts +22 -0
  142. package/dist/shared/run/browser.d.ts +22 -0
  143. package/dist/shared/run/browser.js +74 -0
  144. package/dist/shared/state/index.cjs +38 -0
  145. package/dist/shared/state/index.d.cts +2 -0
  146. package/dist/shared/state/index.d.ts +2 -0
  147. package/dist/shared/state/index.js +16 -0
  148. package/dist/shared/state/session-state.cjs +85 -0
  149. package/dist/shared/state/session-state.d.cts +34 -0
  150. package/dist/shared/state/session-state.d.ts +34 -0
  151. package/dist/shared/state/session-state.js +56 -0
  152. package/dist/shared/visualization/ghost-cursor.cjs +174 -0
  153. package/dist/shared/visualization/ghost-cursor.d.cts +37 -0
  154. package/dist/shared/visualization/ghost-cursor.d.ts +37 -0
  155. package/dist/shared/visualization/ghost-cursor.js +145 -0
  156. package/dist/shared/visualization/highlight.cjs +134 -0
  157. package/dist/shared/visualization/highlight.d.cts +22 -0
  158. package/dist/shared/visualization/highlight.d.ts +22 -0
  159. package/dist/shared/visualization/highlight.js +108 -0
  160. package/dist/shared/visualization/index.cjs +45 -0
  161. package/dist/shared/visualization/index.d.cts +3 -0
  162. package/dist/shared/visualization/index.d.ts +3 -0
  163. package/dist/shared/visualization/index.js +24 -0
  164. package/dist/shared/workflow/workflow.cjs +47 -0
  165. package/dist/shared/workflow/workflow.d.cts +33 -0
  166. package/dist/shared/workflow/workflow.d.ts +33 -0
  167. package/dist/shared/workflow/workflow.js +21 -0
  168. package/package.json +123 -26
  169. package/.npmignore +0 -2
  170. package/bin/libretto +0 -31
  171. package/lib/connect.js +0 -34
  172. package/lib/export.js +0 -224
  173. package/lib/import.js +0 -166
  174. package/lib/index.js +0 -8
  175. package/lib/log.js +0 -9
  176. package/lib/validate.js +0 -20
  177. package/makefile +0 -8
  178. package/src/connect.coffee +0 -25
  179. package/src/export.coffee +0 -222
  180. package/src/import.coffee +0 -166
  181. package/src/index.coffee +0 -3
  182. package/src/log.coffee +0 -3
  183. package/src/validate.coffee +0 -10
package/lib/import.js DELETED
@@ -1,166 +0,0 @@
1
- // Generated by CoffeeScript 1.7.0
2
- (function() {
3
- var ObjectID, async, connect, fs, glob, importFixtures, insertItems, loadData, loadFixtures, mkdirp, outcome, path, readline, removeExplicit, removeReferences, stepc, traverse, validate, _log, _types;
4
-
5
- stepc = require("stepc");
6
-
7
- outcome = require("outcome");
8
-
9
- async = require("async");
10
-
11
- mkdirp = require("mkdirp");
12
-
13
- glob = require("glob");
14
-
15
- fs = require("fs");
16
-
17
- readline = require("readline");
18
-
19
- path = require("path");
20
-
21
- traverse = require("traverse");
22
-
23
- validate = require("./validate");
24
-
25
- connect = require("./connect");
26
-
27
- ObjectID = require("mongodb").ObjectID;
28
-
29
- _log = require("./log");
30
-
31
- _types = {
32
- ObjectID: ObjectID,
33
- Date: Date
34
- };
35
-
36
-
37
- /*
38
- */
39
-
40
- module.exports = function(options, next) {
41
- var o, _ref;
42
- o = outcome.e(next);
43
- process.env.LOG_LIBRETTO = (_ref = options.verbose) != null ? _ref : process.env.LOG_LIBRETTO;
44
- return stepc.async(o.s(function() {
45
- return connect({
46
- db: options.db
47
- }, this);
48
- }), o.s(function(db) {
49
- this.db = db;
50
- return this();
51
- }), o.s(function() {
52
- return loadData(options, this);
53
- }), o.s(function(data) {
54
- return importFixtures(data, this.db, this);
55
- }), next);
56
- };
57
-
58
- loadData = function(options, next) {
59
- var collectionFiles, data;
60
- if (options.data) {
61
- return next(null, options.data);
62
- }
63
- collectionFiles = glob.sync(options.path).filter(function(name) {
64
- return !/.DS_Store/.test(name) && /(json|js)$/.test(name);
65
- });
66
- data = [];
67
- collectionFiles.forEach(function(fp) {
68
- return data = data.concat(require(fp));
69
- });
70
- return next(null, data);
71
- };
72
-
73
-
74
- /*
75
- */
76
-
77
- importFixtures = function(data, db, next) {
78
- var o;
79
- o = outcome.e(next);
80
- return stepc.async((function() {
81
- return loadFixtures(data, this);
82
- }), o.s(function(items) {
83
- this.items = items;
84
- return removeReferences(db, items, this);
85
- }), o.s(function() {
86
- return removeExplicit(db, this.items, this);
87
- }), o.s(function() {
88
- return insertItems(db, this.items, this);
89
- }), next);
90
- };
91
-
92
- loadFixtures = function(items, next) {
93
- return next(null, items.map(function(item) {
94
- traverse(item.data).forEach(function(x) {
95
- if (x && x.__type) {
96
- return this.update(new _types[x.__type](x.value));
97
- }
98
- });
99
- return item;
100
- }));
101
- };
102
-
103
- removeExplicit = function(db, items, next) {
104
- var rm;
105
- rm = items.filter(function(item) {
106
- return item.method === "remove";
107
- });
108
- return async.eachSeries(rm, (function(item, next) {
109
- _log("remove %s %s", item.collection, JSON.stringify(item.query));
110
- return db.collection(item.collection).remove(item.query, next);
111
- }), next);
112
- };
113
-
114
- removeReferences = function(db, items, next) {
115
- return async.eachSeries(items, function(item, next) {
116
- var collection, keys, refs;
117
- refs = [];
118
- for (collection in item.refs) {
119
- keys = item.refs[collection];
120
- refs.push.apply(refs, keys.map(function(key) {
121
- return {
122
- collection: collection,
123
- field: key
124
- };
125
- }));
126
- }
127
- return async.eachSeries(refs, (function(ref, next) {
128
- var search;
129
- search = {};
130
- search[ref.field] = item.data._id;
131
- _log("remove %s:%s.%s", ref.collection, item.data._id, ref.field);
132
- return db.collection(ref.collection).remove(search, next);
133
- }), next);
134
- }, next);
135
- };
136
-
137
-
138
- /*
139
- */
140
-
141
- insertItems = function(db, items, next) {
142
- items = items.filter(function(item) {
143
- return item.method === "insert";
144
- });
145
- async.eachSeries(items, (function(item, next) {
146
- if (/^system/.test(item.collection)) {
147
- return next();
148
- }
149
- _log("insert %s:%s", item.collection, item.data._id);
150
- return db.collection(item.collection).insert(item.data, function(err) {
151
- if (err) {
152
- _log(err);
153
- }
154
- return next();
155
- });
156
- }), next);
157
- return function(fixturePath, next) {
158
- var collectionName, results;
159
- collectionName = path.basename(fixturePath).split(".").shift();
160
- _log("importing %s", collectionName);
161
- results = require(fixturePath);
162
- return importItems(results, db, next);
163
- };
164
- };
165
-
166
- }).call(this);
package/lib/index.js DELETED
@@ -1,8 +0,0 @@
1
- // Generated by CoffeeScript 1.7.0
2
- (function() {
3
- module.exports = {
4
- "import": require("./import"),
5
- "export": require("./export")
6
- };
7
-
8
- }).call(this);
package/lib/log.js DELETED
@@ -1,9 +0,0 @@
1
- // Generated by CoffeeScript 1.7.0
2
- (function() {
3
- module.exports = function() {
4
- if (['true', true, 1].indexOf(process.env.LOG_LIBRETTO) !== -1) {
5
- return console.log.apply(console, arguments);
6
- }
7
- };
8
-
9
- }).call(this);
package/lib/validate.js DELETED
@@ -1,20 +0,0 @@
1
- // Generated by CoffeeScript 1.7.0
2
- (function() {
3
- var verify;
4
-
5
- verify = require("verify");
6
-
7
-
8
- /*
9
- validates options for import / export
10
- */
11
-
12
- module.exports = function(options, next) {
13
- if (!verify().that(options).onError(next).has("path", "db").success) {
14
- return;
15
- }
16
- options.path = options.path.replace("~", process.env.HOME);
17
- return next();
18
- };
19
-
20
- }).call(this);
package/makefile DELETED
@@ -1,8 +0,0 @@
1
- all:
2
- coffee -o lib -c src;
3
-
4
- all-watch:
5
- coffee -o lib -cw src;
6
-
7
- clean:
8
- rm -rf lib;
@@ -1,25 +0,0 @@
1
- mongodb = require("mongodb")
2
- client = mongodb.MongoClient
3
- step = require "step"
4
- memoize = require "memoizee"
5
- _log = require "./log"
6
-
7
- ###
8
- connects to the database
9
- ###
10
-
11
- connect = memoize(((db, next) ->
12
- # assume it's a local db if mongodb:// isn't present
13
- unless ~db.indexOf("mongodb://")
14
- db = "mongodb://127.0.0.1:27017/" + db
15
-
16
- _log("connecting to %s", db)
17
-
18
- client.connect db, next
19
- ), { async: true })
20
-
21
-
22
-
23
- module.exports = (options, next) ->
24
- connect options.db, next
25
-
package/src/export.coffee DELETED
@@ -1,222 +0,0 @@
1
- stepc = require "stepc"
2
- outcome = require "outcome"
3
- async = require "async"
4
- mkdirp = require "mkdirp"
5
- fs = require "fs"
6
- type = require "type-component"
7
- traverse = require "traverse"
8
-
9
- validate = require "./validate"
10
- connect = require "./connect"
11
- mongodb = require("mongodb")
12
- _log = require "./log"
13
-
14
-
15
-
16
- ###
17
- ###
18
-
19
- module.exports = (options, next) ->
20
-
21
- o = outcome.e next
22
-
23
- stepc.async(
24
-
25
- # make the directory
26
- o.s(() ->
27
- try
28
- mkdirp.sync options.path
29
- catch e
30
- @()
31
- ),
32
-
33
- # connect to mongodb
34
- o.s(() ->
35
- connect({ db: options.db }, @)
36
- ),
37
-
38
- # get all the collection names
39
- o.s((@db) ->
40
- db.collectionNames @
41
- ),
42
-
43
-
44
- # start the export process
45
- o.s((names) ->
46
-
47
- collections = names.map (data) =>
48
-
49
- @db.collection data.name.split(".").slice(1).join(".")
50
-
51
- exportCollections options, collections, @
52
- ),
53
-
54
- # done
55
- next
56
- )
57
-
58
- ###
59
- ###
60
-
61
- exportCollections = (options, collections, next) ->
62
- loadCollections collections, (err, collections) ->
63
- mapItemRelationships collections
64
- async.eachSeries collections, exportCollection(options), next
65
-
66
-
67
- ###
68
- ###
69
-
70
- mapItemRelationships = (collections) ->
71
-
72
- _log("mapping item relationships")
73
-
74
- all = {}
75
-
76
- # first grab all the items
77
- for collection in collections
78
- for item in collection.items
79
- all[item.data._id] = item
80
-
81
- # create
82
- for key of all
83
- item = all[key]
84
- attachRefs(item, all, collections)
85
-
86
-
87
-
88
-
89
-
90
- attachRefs = (item, all) ->
91
-
92
- keys = []
93
-
94
-
95
- traverse(item.data).forEach (x) ->
96
- keys = []
97
-
98
- p = this
99
-
100
-
101
- while p
102
- if isNaN(p.key) and p.key
103
- keys.unshift p.key
104
- p = p.parent
105
-
106
- key = keys.join(".")
107
-
108
-
109
- if ref = all[x]
110
- refs = ref.refs
111
-
112
- unless r = refs[item.collection]
113
- r = refs[item.collection] = []
114
-
115
- unless ~r.indexOf(key)
116
- r.push key
117
-
118
-
119
- if x and typeof x is "object" and not /^(Array|Object)$/.test x.constructor.name
120
- this.update { __type: x.constructor.name, value: x }
121
- this.block()
122
-
123
-
124
- ###
125
- ###
126
-
127
- attachRefs2 = (item, all, current, keys = []) ->
128
-
129
- unless current
130
- current = item
131
-
132
- for key of current
133
-
134
- value = current[key]
135
-
136
- if (ref = all[value])
137
- kp = keys.concat(key).join(".")
138
-
139
- refs = ref.__refs
140
-
141
-
142
- unless r = refs[item.__collection]
143
- r = refs[item.__collection] = []
144
-
145
- unless ~r.indexOf(kp)
146
- r.push kp
147
-
148
- else if (t = type(value)) is "array"
149
- for sub in value
150
- if sub
151
- attachRefs(item, all, sub, keys.concat(key))
152
- else if t is "object" and value
153
- attachRefs(item, all, value, keys.concat())
154
-
155
- if value and (typeof value is "object") and not /^Array|Object$/.test value.constructor.name
156
- current[key] = { __type: value.constructor.name, value: value }
157
-
158
-
159
- refs
160
-
161
-
162
- ###
163
- ###
164
-
165
- loadCollections = (collections, next) ->
166
-
167
- data = []
168
-
169
-
170
- async.eachSeries collections, ((collection, next) ->
171
- collection.find().toArray((err, result) ->
172
- return next(err) if err?
173
-
174
- _log "loaded %s (%d)", collection.collectionName, result.length
175
-
176
- data.push({
177
- name: collection.collectionName,
178
- items: result.map((item) ->
179
- {
180
- data: item
181
- collection: collection.collectionName
182
- refs: {}
183
- method: "insert"
184
- }
185
- )
186
- })
187
-
188
- next()
189
- )
190
- ), (err) ->
191
- return next(err) if err?
192
- next null, data
193
-
194
-
195
-
196
- ###
197
- ###
198
-
199
- exportCollection = (options) ->
200
- (collection, next) ->
201
-
202
- path = options.path + "/" + collection.name + ".json"
203
-
204
- _log("exporting %s", collection.name);
205
-
206
- o = outcome.e next
207
-
208
- return next() if collection.items.length is 0
209
-
210
- stepc.async(
211
-
212
- # save
213
- o.s((results) ->
214
- fs.writeFile(path, JSON.stringify(collection.items, null, 2), @)
215
- ),
216
-
217
- # done
218
- next
219
- )
220
-
221
-
222
-
package/src/import.coffee DELETED
@@ -1,166 +0,0 @@
1
- stepc = require "stepc"
2
- outcome = require "outcome"
3
- async = require "async"
4
- mkdirp = require "mkdirp"
5
- glob = require "glob"
6
- fs = require "fs"
7
- readline = require "readline"
8
- path = require "path"
9
- traverse = require "traverse"
10
-
11
- validate = require "./validate"
12
- connect = require "./connect"
13
- ObjectID = require("mongodb").ObjectID
14
- _log = require "./log"
15
-
16
-
17
- _types = {
18
- ObjectID: ObjectID,
19
- Date: Date
20
- }
21
-
22
-
23
- ###
24
- ###
25
-
26
- module.exports = (options, next) ->
27
-
28
- o = outcome.e(next)
29
-
30
- # yuck
31
- process.env.LOG_LIBRETTO = options.verbose ? process.env.LOG_LIBRETTO
32
-
33
- stepc.async(
34
-
35
- # connect to mongodb
36
- o.s(() ->
37
- connect({ db: options.db }, @)
38
- ),
39
-
40
- #import the collections
41
- o.s((@db) ->
42
- @()
43
- ),
44
-
45
- # load the collection paths
46
- o.s(() ->
47
- loadData options, @
48
- )
49
-
50
- #
51
- o.s((data) ->
52
- importFixtures data, @db, @
53
- ),
54
-
55
- #
56
- next
57
- )
58
-
59
-
60
- loadData = (options, next) ->
61
-
62
- if options.data
63
- return next(null, options.data)
64
-
65
-
66
- collectionFiles = glob.sync(options.path).filter (name) ->
67
- not /.DS_Store/.test(name) and /(json|js)$/.test(name)
68
-
69
-
70
- data = []
71
-
72
- collectionFiles.forEach (fp) ->
73
- data = data.concat require fp
74
-
75
-
76
- next null, data
77
-
78
- ###
79
- ###
80
-
81
- importFixtures = (data, db, next) ->
82
-
83
- o = outcome.e next
84
-
85
- stepc.async(
86
- (() ->
87
- loadFixtures data, @
88
- ),
89
- o.s((@items) ->
90
- removeReferences db, items, @
91
- ),
92
- o.s(() ->
93
- removeExplicit db, @items, @
94
- ),
95
- o.s(() ->
96
- insertItems db, @items, @
97
- ),
98
- next
99
- )
100
-
101
-
102
- loadFixtures = (items, next) ->
103
-
104
- next null, items.map (item) ->
105
- # fix the object type
106
- traverse(item.data).forEach (x) ->
107
- if x and x.__type
108
- this.update(new _types[x.__type](x.value))
109
- item
110
-
111
- removeExplicit = (db, items, next) ->
112
- rm = items.filter (item) -> item.method is "remove"
113
- async.eachSeries rm, ((item, next) ->
114
- _log("remove %s %s", item.collection, JSON.stringify(item.query));
115
- db.collection(item.collection).remove(item.query, next);
116
- ), next
117
-
118
-
119
- removeReferences = (db, items, next) ->
120
- async.eachSeries items, (item, next) ->
121
-
122
- refs = []
123
-
124
- for collection of item.refs
125
- keys = item.refs[collection]
126
- refs.push keys.map((key) -> { collection: collection, field: key })...
127
-
128
- async.eachSeries refs, ((ref, next) ->
129
- search = {}
130
-
131
- # object id might be a string, or object id instance
132
- search[ref.field] = item.data._id
133
- _log("remove %s:%s.%s", ref.collection, item.data._id, ref.field);
134
- db.collection(ref.collection).remove(search, next)
135
- ), next
136
- , next
137
-
138
-
139
-
140
- ###
141
- ###
142
-
143
- insertItems = (db, items, next) ->
144
-
145
- items = items.filter (item) -> item.method is "insert"
146
-
147
- async.eachSeries items, ((item, next) ->
148
-
149
- return next() if /^system/.test item.collection
150
-
151
-
152
- _log("insert %s:%s", item.collection, item.data._id)
153
- db.collection(item.collection).insert(item.data, (err) ->
154
- if err
155
- _log err
156
- next()
157
- )
158
- ), next
159
-
160
- (fixturePath, next) ->
161
- collectionName = path.basename(fixturePath).split(".").shift()
162
- _log "importing %s", collectionName
163
-
164
- results = require(fixturePath)
165
- importItems results, db, next
166
-
package/src/index.coffee DELETED
@@ -1,3 +0,0 @@
1
- module.exports =
2
- import: require("./import")
3
- export: require("./export")
package/src/log.coffee DELETED
@@ -1,3 +0,0 @@
1
- module.exports = () ->
2
- if ['true', true, 1].indexOf(process.env.LOG_LIBRETTO) != -1
3
- console.log arguments...
@@ -1,10 +0,0 @@
1
- verify = require "verify"
2
-
3
- ###
4
- validates options for import / export
5
- ###
6
-
7
- module.exports = (options, next) ->
8
- return unless verify().that(options).onError(next).has("path", "db").success
9
- options.path = options.path.replace("~", process.env.HOME);
10
- next()