alchemy 0.0.8 → 0.1.1

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 (105) hide show
  1. package/package.json +23 -22
  2. package/src/alchemize.ts +151 -0
  3. package/src/apply.ts +117 -0
  4. package/src/components/agent/agent.ts +45 -0
  5. package/src/components/agent/anthropic.ts +27 -0
  6. package/src/components/agent/index.ts +4 -0
  7. package/src/components/agent/model.ts +22 -0
  8. package/src/components/agent/openai.ts +44 -0
  9. package/src/components/agent/package.ts +126 -0
  10. package/src/components/agent/requirements.ts +111 -0
  11. package/src/components/agent/scrape.ts +47 -0
  12. package/src/components/agent/tsconfig.ts +150 -0
  13. package/src/components/agent/typescript.ts +177 -0
  14. package/src/components/aws/bucket.ts +168 -0
  15. package/src/components/aws/function.ts +302 -0
  16. package/src/components/aws/index.ts +6 -0
  17. package/src/components/aws/policy.ts +245 -0
  18. package/src/components/aws/queue.ts +222 -0
  19. package/src/components/aws/role.ts +245 -0
  20. package/src/components/aws/table.ts +172 -0
  21. package/src/components/esbuild.ts +128 -0
  22. package/src/components/fs.ts +45 -0
  23. package/src/destroy.ts +63 -0
  24. package/src/error.ts +16 -0
  25. package/src/global.ts +72 -0
  26. package/src/index.ts +6 -0
  27. package/src/input.ts +16 -0
  28. package/src/main.ts +34 -0
  29. package/src/output.ts +49 -0
  30. package/src/resource.ts +313 -0
  31. package/src/state.ts +100 -0
  32. package/test/aws/function.test.ts +144 -0
  33. package/test/aws/queue.test.ts +85 -0
  34. package/test/aws/role.test.ts +153 -0
  35. package/test/aws/table.test.ts +73 -0
  36. package/test/esbuild.test.ts +41 -0
  37. package/test/handler.ts +9 -0
  38. package/tsconfig.json +7 -0
  39. package/Column.js +0 -1
  40. package/Create.js +0 -1
  41. package/Delete.js +0 -1
  42. package/Drop.js +0 -1
  43. package/Insert.js +0 -1
  44. package/Makefile +0 -8
  45. package/README.md +0 -0
  46. package/Select.js +0 -1
  47. package/Table.js +0 -1
  48. package/Transaction.js +0 -1
  49. package/Types.js +0 -1
  50. package/Update.js +0 -1
  51. package/alchemy.js +0 -57
  52. package/alchemy.sublime-project +0 -9
  53. package/alchemy.sublime-workspace +0 -2304
  54. package/config/app.js +0 -8
  55. package/config/db.js +0 -20
  56. package/copy.js +0 -1
  57. package/defaultEngine.js +0 -8
  58. package/engine.js +0 -282
  59. package/getInstantiatorFunction.js +0 -28
  60. package/index.js +0 -52
  61. package/jstest.js +0 -3
  62. package/loggerFactory.js +0 -27
  63. package/logs/alchemy.log +0 -46
  64. package/logs/sql.log +0 -41
  65. package/sql/Column.js +0 -158
  66. package/sql/Columnable.js +0 -21
  67. package/sql/Create.js +0 -15
  68. package/sql/Delete.js +0 -34
  69. package/sql/Drop.js +0 -36
  70. package/sql/Insert.js +0 -96
  71. package/sql/SchemaElement.js +0 -11
  72. package/sql/Select.js +0 -192
  73. package/sql/SqlBase.js +0 -134
  74. package/sql/SqlStatement.js +0 -80
  75. package/sql/Table.js +0 -96
  76. package/sql/Transaction.js +0 -45
  77. package/sql/Update.js +0 -105
  78. package/sql/defineElement.js +0 -26
  79. package/sql/defineStatement.js +0 -26
  80. package/sql/types/BaseType.js +0 -43
  81. package/sql/types/BigSerialType.js +0 -5
  82. package/sql/types/IntegerType.js +0 -5
  83. package/sql/types/JsonType.js +0 -5
  84. package/sql/types/SerialType.js +0 -5
  85. package/sql/types/StringType.js +0 -31
  86. package/sql/types/TimestampType.js +0 -5
  87. package/sql/types/UUIDType.js +0 -5
  88. package/sql/types/defineType.js +0 -25
  89. package/sql/types/getType.js +0 -12
  90. package/sql/types/index.js +0 -11
  91. package/sql/where.js +0 -31
  92. package/sql/whereToString.js +0 -29
  93. package/test/ColumnTests.js +0 -80
  94. package/test/CreateTable.js +0 -54
  95. package/test/DeleteTests.js +0 -28
  96. package/test/DropTests.js +0 -23
  97. package/test/GetTypeTests.js +0 -56
  98. package/test/InsertTests.js +0 -86
  99. package/test/SelectExistsTests.js +0 -26
  100. package/test/SelectTests.js +0 -130
  101. package/test/TableTests.js +0 -46
  102. package/test.js +0 -8
  103. package/test.ls +0 -4
  104. package/validate.js +0 -26
  105. package/x.js +0 -5
package/sql/Column.js DELETED
@@ -1,158 +0,0 @@
1
- var defineElement = require('./defineElement')
2
- var Types = require('./types')
3
- var getType = require('./types/getType')
4
-
5
- var unref = function(obj){
6
- return JSON.parse(JSON.stringify(obj))
7
- }
8
-
9
- var Column = defineElement('column', {
10
-
11
- statics: {
12
- fromState: function(state){
13
- var result = new this(state.name, state.type, state.options)
14
-
15
- result.metadata = state.metadata
16
-
17
- return result
18
- },
19
-
20
- count: function(col){
21
- var result = col.clone()
22
-
23
- result.name = 'COUNT(' + col.name + ')'
24
-
25
- return result
26
- }
27
- },
28
-
29
- appendStateProperties: function(props){
30
- props.push('type', 'options', 'metadata')
31
- },
32
-
33
- /**
34
- * @param {String} name a name for the column
35
- * @param {Type}
36
- * @param {Object} [options]
37
- * @param {Boolean} [options.primaryKey=false]
38
- * @param {Boolean} [options.nullable=true]
39
- */
40
- init: function(name, type, options){
41
-
42
- this.callSuper()
43
-
44
- this.name = name
45
-
46
- if (type){
47
- //since type can be a json description
48
- //we need to do this in order to ensure an instance
49
- //of the given type
50
- type = unref(type)
51
- var TypeClass = getType(type)
52
- var logger = require('../loggerFactory')()
53
-
54
- logger.info('No Type found for ' + type)
55
-
56
- if (TypeClass){
57
- this.type = TypeClass.fromState(type)
58
- }
59
- }
60
-
61
- this.options = options || {}
62
- this.metadata = {}
63
-
64
- return this
65
- },
66
-
67
- get tableName(){
68
- return this.metadata.tableName
69
- },
70
-
71
- setTable: function(table){
72
- this.metadata.tableName = typeof table == 'string'?
73
- table:
74
- table.name
75
-
76
- return this
77
- },
78
-
79
- jsonField: function(name){
80
- var clone = this.clone()
81
-
82
- name = this.validate(name)
83
-
84
- clone.name += '->>\'' + name + '\''
85
-
86
- return clone
87
- },
88
-
89
- as: function(name){
90
- var clone = this.clone()
91
-
92
- clone.options.selectAs = name
93
-
94
- return clone
95
- },
96
-
97
- nextSequence: function(name){
98
- var clone = this.clone()
99
-
100
- name = name || this.tableName + '_' + this.name + '_seq'
101
-
102
- clone.name = 'nextval(\'' + name + '\')'
103
- delete clone.metadata.tableName
104
-
105
- return clone
106
- },
107
-
108
- count: function(){
109
- return Column.count(this)
110
- },
111
-
112
- checkType: function(type){
113
- if (!this.isValidType(type)){
114
- console.error('Unknown column type ' + type + '!')
115
- }
116
- },
117
-
118
- isValidType: function(type){
119
- type = type || this.type
120
-
121
- var k
122
- var Type
123
-
124
- for (k in Types){
125
- Type = Types[k]
126
-
127
- if (type === Type || (type instanceof Type)){
128
- return true
129
- }
130
- }
131
-
132
- return false
133
- },
134
-
135
- asCreate: function(){
136
- var result = this.name + ' ' + this.type.toString()
137
-
138
- if (this.options.primaryKey){
139
- result += ' PRIMARY KEY'
140
- }
141
-
142
- if (this.options.unique){
143
- result += ' UNIQUE'
144
- }
145
-
146
- if (this.options.notNull){
147
- result += ' NOT NULL'
148
- }
149
-
150
- if (this.options['default']){
151
- result += ' DEFAULT ' + this.options['default']
152
- }
153
-
154
- return result
155
- }
156
- })
157
-
158
- module.exports = Column
package/sql/Columnable.js DELETED
@@ -1,21 +0,0 @@
1
- var classy = require('classy')
2
-
3
- module.exports = classy.defineMixin({
4
-
5
- $after: {
6
- appendStateProperties: function(props){
7
- props.push('columns')
8
- }
9
- },
10
-
11
- $before: {
12
- prepareColumns: function(columns){
13
-
14
- if (!Array.isArray(columns)){
15
- columns = [].slice.call(arguments, 0)
16
- }
17
-
18
- this.columns = columns
19
- }
20
- }
21
- })
package/sql/Create.js DELETED
@@ -1,15 +0,0 @@
1
- module.exports = require('./defineStatement')('create', {
2
-
3
- init: function(what){
4
- this.callSuper()
5
- this.target = what
6
- },
7
-
8
- toString: function(){
9
- if (this.target && typeof this.target.createToString == 'function'){
10
- return this.target.createToString()
11
- }
12
-
13
- return 'CREATE ' + this.target
14
- }
15
- })
package/sql/Delete.js DELETED
@@ -1,34 +0,0 @@
1
- module.exports = require('./defineStatement')('delete', {
2
-
3
- init: function(what){
4
- this.callSuper()
5
- this.target = what
6
- },
7
-
8
- toString: function(){
9
-
10
- var from = this.fromToString()
11
- var where = this.whereToString()
12
-
13
- return 'DELETE ' + from + where
14
- },
15
-
16
- appendStateProperties: function(props){
17
- props.push('target', 'whereConditions')
18
- },
19
-
20
- fromToString: function(){
21
- var target = ''
22
-
23
- if (typeof this.target == 'string'){
24
- target = this.target
25
- } else {
26
- target = this.target.name
27
- }
28
-
29
- return 'FROM ' + target
30
- },
31
-
32
- whereToString: require('./whereToString'),
33
- where : require('./where')
34
- })
package/sql/Drop.js DELETED
@@ -1,36 +0,0 @@
1
- module.exports = require('./defineStatement')('delete', {
2
-
3
- init: function(){
4
- this.callSuper()
5
- },
6
-
7
- toString: function(){
8
-
9
- var what = this.whatToString()
10
-
11
- return 'DROP ' + what
12
- },
13
-
14
- appendStateProperties: function(props){
15
- props.push('target')
16
- },
17
-
18
- table: function(target){
19
- this.name = 'TABLE'
20
- this.target = target
21
-
22
- return this
23
- },
24
-
25
- targetToString: function(){
26
- return typeof this.target == 'string'?
27
- this.target:
28
- this.target.name?
29
- this.target.name:
30
- this.target.toString()
31
- },
32
-
33
- whatToString: function(){
34
- return this.name + ' ' + this.targetToString()
35
- }
36
- })
package/sql/Insert.js DELETED
@@ -1,96 +0,0 @@
1
- module.exports = require('./defineStatement')('insert', {
2
-
3
- mixins: [
4
- require('./Columnable')
5
- ],
6
-
7
- init: function(){
8
- this.callSuper()
9
- this.prepareColumns.apply(this, arguments)
10
- },
11
-
12
- toString: function(){
13
- var into = this.targetToString()
14
- var cols = this.columnsToString()
15
- var values = this.valuesToString()
16
-
17
- return 'INSERT INTO ' + into + ' ' + cols + ' VALUES ' + values + ';'
18
- },
19
-
20
- getInsertColumns: function(){
21
- var cols = []
22
-
23
- this.values.forEach(function(values){
24
- Object.keys(values).forEach(function(k){
25
- if (!~cols.indexOf(k)){
26
- cols.push(k)
27
- }
28
- })
29
- })
30
-
31
- return cols
32
- },
33
-
34
- valuesToString: function(){
35
- var cols = this.getInsertColumns()
36
-
37
- return this.values.map(function(values){
38
-
39
- var result = cols.map(function(colName){
40
- return this.valueToSql(values[colName])
41
- }, this)
42
-
43
- return '(' + result.join(', ') + ')'
44
- }, this).join(', ')
45
- },
46
-
47
- columnsToString: function(){
48
- return '(' + this.getInsertColumns().join(', ') + ')'
49
- },
50
-
51
- targetToString: function() {
52
- var into = this.intoTarget
53
-
54
- if (!into){
55
- this.columns.some(function(c){
56
- if (c.tableName){
57
- into = c.tableName
58
- return true
59
- }
60
- })
61
- }
62
-
63
- return into
64
- },
65
-
66
- values: function(values){
67
- this.values = Array.isArray(values)?
68
- values:
69
- [values]
70
-
71
- var cols = {}
72
- this.columns.forEach(function(col){
73
- cols[col.name] = 1
74
- })
75
-
76
- this.values = this.values.map(function(values){
77
- var validValues = {}
78
- var count = 0
79
-
80
- Object.keys(values).forEach(function(k){
81
- if (k in cols){
82
- validValues[k] = values[k]
83
- count++
84
- }
85
- })
86
-
87
- return count? validValues: null
88
- })
89
-
90
- this.values = this.values.filter(function(v){
91
- return !!v
92
- })
93
-
94
- return this
95
- }
96
- })
@@ -1,11 +0,0 @@
1
- var classy = require('classy')
2
-
3
- module.exports = classy.define({
4
-
5
- extend: require('./SqlBase'),
6
- alias : 'schema.SchemaElement',
7
-
8
- stateProperties: [
9
- 'name'
10
- ]
11
- })
package/sql/Select.js DELETED
@@ -1,192 +0,0 @@
1
- 'use strict'
2
-
3
- var F = require('functionally')
4
- var defineStatement = require('./defineStatement')
5
-
6
- var map = F.map
7
- var dot = F.dot
8
- var compose = F.compose
9
-
10
- module.exports = defineStatement('select', {
11
-
12
- mixins: [
13
- require('./Columnable')
14
- ],
15
-
16
- statics: {
17
- fromState: function(state){
18
- var inst = new this(state.columns)
19
-
20
- inst.copy(state)
21
- inst.state = state
22
-
23
- return inst
24
- }
25
- },
26
-
27
- appendStateProperties: function(props){
28
- props.push('selectLimit', 'selectOffset', 'selectExists', 'whereConditions')
29
- },
30
-
31
- init: function(columns){
32
- this.callSuper()
33
- this.prepareColumns.apply(this, arguments)
34
- },
35
-
36
- setColumns: function(){
37
- this.prepareColumns.apply(this, arguments)
38
-
39
- return this
40
- },
41
-
42
- addColumn: function(column){
43
- this.columns.push(column)
44
-
45
- return this
46
- },
47
-
48
- limit: function(limit){
49
- if (limit * 1 == limit){
50
- this.selectLimit = limit
51
- }
52
-
53
- return this
54
- },
55
-
56
- offset: function(offset){
57
- if (offset * 1 == offset){
58
- this.selectOffset = offset
59
- }
60
-
61
- return this
62
- },
63
-
64
- /**
65
- * Tell the select to return the given page. Pages starting from 1.
66
- *
67
- * @param {Number/String} page
68
- * @return {Select}
69
- */
70
- page: function(page){
71
- if (page * 1 == page){
72
- this.selectPage = page
73
- }
74
-
75
- return this
76
- },
77
-
78
- pageSize: function(size){
79
- return this.limit(size)
80
- },
81
-
82
- toString: function(){
83
- return this.valueOf({
84
- parameterized: false
85
- })
86
- },
87
-
88
- limitToString: function() {
89
- var limit = this.selectLimit? ' LIMIT ' + this.selectLimit: ''
90
-
91
- return limit
92
- },
93
-
94
- offsetToString: function(){
95
- if (this.selectPage && this.selectLimit){
96
- this.selectOffset = (this.selectPage - 1) * this.selectLimit
97
- }
98
-
99
- var offset = this.selectOffset? ' OFFSET ' + this.selectOffset: ''
100
-
101
- return offset
102
- },
103
-
104
- prepareColumns: function(){
105
- //columns are already set
106
-
107
- var from = this.state.from
108
-
109
- if (!from){
110
- this.columns.some(function(c){
111
- if (c.tableName){
112
- this.state.from = c.tableName
113
- return true
114
- }
115
- }, this)
116
- }
117
- },
118
-
119
- valueOf: function(config){
120
- if (this.selectExists){
121
- return 'SELECT EXISTS(' + this.selectExists + ')'
122
- }
123
-
124
- var from = this.fromToString()
125
- var cols = this.columnsToString()
126
- var where = this.whereToString(config)
127
- var limit = this.limitToString()
128
- var offset = this.offsetToString()
129
-
130
- return 'SELECT ' + cols + from + where + limit + offset
131
- },
132
-
133
- from: function(table){
134
- this.state.from = typeof table == 'string'?
135
- table:
136
- table.name
137
-
138
- return this
139
- },
140
-
141
- fromToString: function() {
142
- var from = this.state.from
143
-
144
- if (!from){
145
- this.columns.some(function(c){
146
- if (c.tableName){
147
- from = c.tableName
148
- return true
149
- }
150
- })
151
- }
152
-
153
- return from?
154
- ' FROM ' + from:
155
- ''
156
- },
157
-
158
- columnsToString: function(){
159
- if (!this.columns || this.columns.length == 0){
160
- return '*'
161
- }
162
- return this.columns.map(function(col){
163
- if (typeof col == 'string'){
164
- return col
165
- }
166
-
167
- var name = col.name
168
-
169
- if (col.options && col.options.selectAs){
170
- name += ' AS ' + col.options.selectAs
171
- }
172
-
173
- return name
174
- }).join(', ')
175
- },
176
-
177
- whereToString: require('./whereToString'),
178
-
179
- getParams: function(){
180
- return this.whereConditions.map(compose(this.valueToSql, dot(2)))
181
- },
182
-
183
- exists: function(){
184
- var clone = this.clone()
185
-
186
- clone.selectExists = this
187
-
188
- return clone
189
- },
190
-
191
- where: require('./where')
192
- })
package/sql/SqlBase.js DELETED
@@ -1,134 +0,0 @@
1
- 'use strict'
2
-
3
- var classy = require('classy')
4
-
5
- var copy = require('../copy')
6
- var validate = require('../validate')
7
-
8
- function unique(arr){
9
- var result = []
10
-
11
- arr.forEach(function(value){
12
- if (result.indexOf(value) == -1){
13
- result.push(value)
14
- }
15
- })
16
-
17
- return result
18
- }
19
-
20
- module.exports = classy.define({
21
-
22
- alias: 'sql.Base',
23
-
24
- forceInstance: true,
25
-
26
- stateProperties: [
27
- ],
28
-
29
- statics: {
30
- fromState: function(state){
31
-
32
- }
33
- },
34
-
35
- init: function(){
36
- this.initState()
37
- this.prepareStateProperties()
38
- },
39
-
40
- initState: function(){
41
- this.state = this.state?
42
- copy(this.state):
43
- {}
44
- },
45
-
46
- initStateProperties: function(){
47
-
48
- var props = this.stateProperties
49
-
50
- props = this.stateProperties = unique(props)
51
-
52
- props.forEach(function(name){
53
- Object.defineProperty(this, name, {
54
- get: function(){
55
- return this.state[name]
56
- },
57
- set: function(value){
58
- this.state[name] = value
59
- }
60
- })
61
- }, this)
62
- },
63
-
64
- appendStateProperties: function(props) {
65
- },
66
-
67
- prepareStateProperties: function(){
68
-
69
- this.stateProperties = (this.stateProperties || []).concat()
70
- this.appendStateProperties(this.stateProperties)
71
- this.initStateProperties()
72
- },
73
-
74
- copy: function(obj){
75
- copy(obj, this)
76
-
77
- return this
78
- },
79
-
80
- setState: function(state){
81
- this.state = state
82
- },
83
-
84
- validate: function(name){
85
- return validate(name)
86
- },
87
-
88
- clone: function(){
89
- return this.$ownClass.fromState(this.toState())
90
- },
91
-
92
- getEmptyState: function(){
93
- return {
94
- alias: this.alias
95
- }
96
- },
97
-
98
- toState: function(){
99
- return copy(this.cloneState(), this.getEmptyState())
100
- },
101
-
102
- cloneState: function(){
103
- return this.toJSON()
104
- },
105
-
106
- toJSON: function(){
107
- return JSON.parse(JSON.stringify(this.state))
108
- },
109
-
110
- set: function(name, value){
111
- arguments.length == 1?
112
- copy(obj, this.state):
113
- this.state[name] = value
114
-
115
- return this
116
- },
117
-
118
- get: function(name){
119
- if (typeof name != 'string'){
120
- return Object.keys(name).map(this.get, this)
121
- }
122
-
123
- return this.state[name]
124
- },
125
-
126
- toString: function(){
127
-
128
- },
129
-
130
- valueOf: function(){
131
- return this.toString()
132
- }
133
-
134
- })