-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbasic.js
154 lines (137 loc) · 3.51 KB
/
basic.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Copyright (c) 2011-2015 Richard Rodger */
"use strict";
var Path = require("path");
var Note = require("./lib/note");
var Entity = require("./lib/entity");
var Uniqueid = require("./lib/uniqueid");
var Common = require("./lib/common");
function registerNote(seneca, note) {
// The note patterns let you pass information to plugins that are
// loaded after the current plugin. See seneca-admin
seneca.add({ role: Common.plugin.name, note: true, cmd: "set" }, note.set);
seneca.add({ role: Common.plugin.name, note: true, cmd: "get" }, note.get);
seneca.add({ role: Common.plugin.name, note: true, cmd: "list" }, note.list);
seneca.add({ role: Common.plugin.name, note: true, cmd: "push" }, note.push);
seneca.add({ role: Common.plugin.name, note: true, cmd: "pop" }, note.pop);
// Legacy cmds use role:'util'
seneca.add(
{
role: "util",
note: true,
cmd: "set",
deprecate$: Common.messages.UTIL_DEPRECATED
},
note.set
);
seneca.add(
{
role: "util",
note: true,
cmd: "get",
deprecate$: Common.messages.UTIL_DEPRECATED
},
note.get
);
seneca.add(
{
role: "util",
note: true,
cmd: "list",
deprecate$: Common.messages.UTIL_DEPRECATED
},
note.list
);
seneca.add(
{
role: "util",
note: true,
cmd: "push",
deprecate$: Common.messages.UTIL_DEPRECATED
},
note.push
);
seneca.add(
{
role: "util",
note: true,
cmd: "pop",
deprecate$: Common.messages.UTIL_DEPRECATED
},
note.pop
);
}
function registerEntity(seneca, entity) {
// TODO: this should be a utility function, not a pattern
seneca.add(
{
role: Common.plugin.name,
cmd: "ensure_entity",
pin: { required$: true },
// TODO: accept entity spec here, e.g. strings like 'sys/user'
entmap: { object$: true, required$: true }
},
entity.ensure
);
seneca.add(
{ role: Common.plugin.name, cmd: "define_sys_entity" },
entity.defineSys
);
// Legacy cmds use role:'util'
seneca.add({ role: "util", cmd: "ensure_entity" }, entity.ensure);
seneca.add({ role: "util", cmd: "define_sys_entity" }, entity.defineSys);
}
function registerUniqueId(seneca) {
seneca.add(
{
role: Common.plugin.name,
cmd: "quickcode",
deprecate$: Common.messages.MARKED_FOR_REMOVAL
},
Uniqueid.quickcode
);
// TODO: this should be a utility function, not a pattern
seneca.add(
{ role: Common.plugin.name, cmd: "generate_id" },
Uniqueid.generate_id
);
// Legacy cmds use role:'util'
seneca.add(
{
role: "util",
cmd: "quickcode",
deprecate$: Common.messages.UTIL_DEPRECATED
},
Uniqueid.quickcode
);
seneca.add({ role: "util", cmd: "generate_id" }, Uniqueid.generate_id);
}
var utilfuncs = {
pathnorm: function(pathstr) {
return Path.normalize(pathstr == null ? "" : "" + pathstr).replace(
/\/+$/,
""
);
}
};
module.exports = function basic(options) {
var seneca = this;
options = seneca.util.deepextend({ limit: { parallel: 11 } }, options);
var note = Note();
var entity = Entity(options);
registerUniqueId(seneca);
registerEntity(seneca, entity);
registerNote(seneca, note);
utilfuncs.deepextend = seneca.util.deepextend;
return {
export: utilfuncs
};
};
module.exports.preload = function() {
var seneca = this;
utilfuncs.deepextend = seneca.util.deepextend;
var meta = {
name: Common.plugin.name,
export: utilfuncs
};
return meta;
};