libretto 0.1.4 → 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 -168
  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 -171
  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,168 +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((function() {
45
- return validate(options, this);
46
- }), o.s(function() {
47
- return connect({
48
- db: options.db
49
- }, this);
50
- }), o.s(function(db) {
51
- this.db = db;
52
- return this();
53
- }), o.s(function() {
54
- return loadData(options, this);
55
- }), o.s(function(data) {
56
- return importFixtures(data, this.db, this);
57
- }), next);
58
- };
59
-
60
- loadData = function(options, next) {
61
- var collectionFiles, data;
62
- if (options.data) {
63
- return next(null, options.data);
64
- }
65
- collectionFiles = glob.sync(options.path).filter(function(name) {
66
- return !/.DS_Store/.test(name) && /(json|js)$/.test(name);
67
- });
68
- data = [];
69
- collectionFiles.forEach(function(fp) {
70
- return data = data.concat(require(fp));
71
- });
72
- return next(null, data);
73
- };
74
-
75
-
76
- /*
77
- */
78
-
79
- importFixtures = function(data, db, next) {
80
- var o;
81
- o = outcome.e(next);
82
- return stepc.async((function() {
83
- return loadFixtures(data, this);
84
- }), o.s(function(items) {
85
- this.items = items;
86
- return removeReferences(db, items, this);
87
- }), o.s(function() {
88
- return removeExplicit(db, this.items, this);
89
- }), o.s(function() {
90
- return insertItems(db, this.items, this);
91
- }), next);
92
- };
93
-
94
- loadFixtures = function(items, next) {
95
- return next(null, items.map(function(item) {
96
- traverse(item.data).forEach(function(x) {
97
- if (x && x.__type) {
98
- return this.update(new _types[x.__type](x.value));
99
- }
100
- });
101
- return item;
102
- }));
103
- };
104
-
105
- removeExplicit = function(db, items, next) {
106
- var rm;
107
- rm = items.filter(function(item) {
108
- return item.method === "remove";
109
- });
110
- return async.eachSeries(rm, (function(item, next) {
111
- _log("remove %s %s", item.collection, JSON.stringify(item.query));
112
- return db.collection(item.collection).remove(item.query, next);
113
- }), next);
114
- };
115
-
116
- removeReferences = function(db, items, next) {
117
- return async.eachSeries(items, function(item, next) {
118
- var collection, keys, refs;
119
- refs = [];
120
- for (collection in item.refs) {
121
- keys = item.refs[collection];
122
- refs.push.apply(refs, keys.map(function(key) {
123
- return {
124
- collection: collection,
125
- field: key
126
- };
127
- }));
128
- }
129
- return async.eachSeries(refs, (function(ref, next) {
130
- var search;
131
- search = {};
132
- search[ref.field] = item.data._id;
133
- _log("remove %s:%s.%s", ref.collection, item.data._id, ref.field);
134
- return db.collection(ref.collection).remove(search, next);
135
- }), next);
136
- }, next);
137
- };
138
-
139
-
140
- /*
141
- */
142
-
143
- insertItems = function(db, items, next) {
144
- items = items.filter(function(item) {
145
- return item.method === "insert";
146
- });
147
- async.eachSeries(items, (function(item, next) {
148
- if (/^system/.test(item.collection)) {
149
- return next();
150
- }
151
- _log("insert %s:%s", item.collection, item.data._id);
152
- return db.collection(item.collection).insert(item.data, function(err) {
153
- if (err) {
154
- _log(err);
155
- }
156
- return next();
157
- });
158
- }), next);
159
- return function(fixturePath, next) {
160
- var collectionName, results;
161
- collectionName = path.basename(fixturePath).split(".").shift();
162
- _log("importing %s", collectionName);
163
- results = require(fixturePath);
164
- return importItems(results, db, next);
165
- };
166
- };
167
-
168
- }).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,171 +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
- # validate fields
36
- (() ->
37
- validate(options, @)
38
- ),
39
-
40
- # connect to mongodb
41
- o.s(() ->
42
- connect({ db: options.db }, @)
43
- ),
44
-
45
- #import the collections
46
- o.s((@db) ->
47
- @()
48
- ),
49
-
50
- # load the collection paths
51
- o.s(() ->
52
- loadData options, @
53
- )
54
-
55
- #
56
- o.s((data) ->
57
- importFixtures data, @db, @
58
- ),
59
-
60
- #
61
- next
62
- )
63
-
64
-
65
- loadData = (options, next) ->
66
-
67
- if options.data
68
- return next(null, options.data)
69
-
70
-
71
- collectionFiles = glob.sync(options.path).filter (name) ->
72
- not /.DS_Store/.test(name) and /(json|js)$/.test(name)
73
-
74
-
75
- data = []
76
-
77
- collectionFiles.forEach (fp) ->
78
- data = data.concat require fp
79
-
80
-
81
- next null, data
82
-
83
- ###
84
- ###
85
-
86
- importFixtures = (data, db, next) ->
87
-
88
- o = outcome.e next
89
-
90
- stepc.async(
91
- (() ->
92
- loadFixtures data, @
93
- ),
94
- o.s((@items) ->
95
- removeReferences db, items, @
96
- ),
97
- o.s(() ->
98
- removeExplicit db, @items, @
99
- ),
100
- o.s(() ->
101
- insertItems db, @items, @
102
- ),
103
- next
104
- )
105
-
106
-
107
- loadFixtures = (items, next) ->
108
-
109
- next null, items.map (item) ->
110
- # fix the object type
111
- traverse(item.data).forEach (x) ->
112
- if x and x.__type
113
- this.update(new _types[x.__type](x.value))
114
- item
115
-
116
- removeExplicit = (db, items, next) ->
117
- rm = items.filter (item) -> item.method is "remove"
118
- async.eachSeries rm, ((item, next) ->
119
- _log("remove %s %s", item.collection, JSON.stringify(item.query));
120
- db.collection(item.collection).remove(item.query, next);
121
- ), next
122
-
123
-
124
- removeReferences = (db, items, next) ->
125
- async.eachSeries items, (item, next) ->
126
-
127
- refs = []
128
-
129
- for collection of item.refs
130
- keys = item.refs[collection]
131
- refs.push keys.map((key) -> { collection: collection, field: key })...
132
-
133
- async.eachSeries refs, ((ref, next) ->
134
- search = {}
135
-
136
- # object id might be a string, or object id instance
137
- search[ref.field] = item.data._id
138
- _log("remove %s:%s.%s", ref.collection, item.data._id, ref.field);
139
- db.collection(ref.collection).remove(search, next)
140
- ), next
141
- , next
142
-
143
-
144
-
145
- ###
146
- ###
147
-
148
- insertItems = (db, items, next) ->
149
-
150
- items = items.filter (item) -> item.method is "insert"
151
-
152
- async.eachSeries items, ((item, next) ->
153
-
154
- return next() if /^system/.test item.collection
155
-
156
-
157
- _log("insert %s:%s", item.collection, item.data._id)
158
- db.collection(item.collection).insert(item.data, (err) ->
159
- if err
160
- _log err
161
- next()
162
- )
163
- ), next
164
-
165
- (fixturePath, next) ->
166
- collectionName = path.basename(fixturePath).split(".").shift()
167
- _log "importing %s", collectionName
168
-
169
- results = require(fixturePath)
170
- importItems results, db, next
171
-
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()