Skip to content

Commit b49765c

Browse files
committed
version 0.0.6 - usesable by pb project
1 parent fb12e5c commit b49765c

21 files changed

+310
-1047
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
out/
22
samples/http
3-
src/
3+
bin
4+
.vscode

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ This is in a very early stage, the most helpful feedback will be on the intuitiv
2626
- Be able to init and create new functions
2727
- Be able to convert old functions to new format.
2828

29+
### Extensibility
30+
- Change getRequiredProperties/getOptionalProperties => getConfig or something and include validation for required.
31+
- Make function name required??
32+
2933
## Challenges
3034
- Requires a "build step" which is not required for plain JavaScript. Luckily, converting JavaScript is fairly common practice.
3135
- Need to verify that integration with other build steps is ok. This should be fine though, as long as this is the last step in any generation pipeline. Thought should be put into making this an intuitive experience.
3236
- Templates. How to make them compatible with existing systems? We want to keep index.js but change function.json. Maybe this ties into work to convert old functions to new.
33-

bindings/core/blobBinding.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { BindingBase, Trigger, InputBinding, OutputBinding } from "../../src/types/bindings/bindings"
1+
import { AzFunctionBindingBase, Trigger, InputBinding, OutputBinding, Binding } from "../../src/types/bindings"
22

33
/**
44
* Blob Binding
55
*/
6-
class BlobBinding extends BindingBase {
6+
class BlobBinding extends AzFunctionBindingBase {
77
/**
88
* The path to the blob container
99
*/
@@ -13,10 +13,6 @@ class BlobBinding extends BindingBase {
1313
*/
1414
public connection: string;
1515

16-
public getRequiredProperties() {
17-
return [...super.getRequiredProperties(), "path", "connection"];
18-
}
19-
2016
constructor(parameters: {
2117
name: string,
2218
path: string,
@@ -27,6 +23,18 @@ class BlobBinding extends BindingBase {
2723
this.path = parameters.path;
2824
this.connection = parameters.connection;
2925
}
26+
27+
public getProperties(): Binding {
28+
const coreProperties = super.getProperties();
29+
if (!this.path) throw new Error("Missing required property 'path'")
30+
if (!this.connection) throw new Error("Missing required property 'connection'")
31+
32+
const blobProperties = {
33+
path: this.path,
34+
connection: this.connection
35+
};
36+
return Object.assign({}, coreProperties, blobProperties);
37+
}
3038
}
3139

3240
export class BlobTrigger extends BlobBinding implements Trigger {

bindings/core/cosmosDbBinding.ts

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { BindingBase, Trigger, InputBinding, OutputBinding } from "../../src/types/bindings/bindings"
1+
import { AzFunctionBindingBase, Trigger, InputBinding, OutputBinding, Binding } from "../../src/types/bindings"
22

33
/**
44
* EventHub Binding
55
*/
6-
class CosmosDbBinding extends BindingBase {
6+
class CosmosDbBinding extends AzFunctionBindingBase {
77
/**
88
*
99
*/
@@ -28,8 +28,17 @@ class CosmosDbBinding extends BindingBase {
2828
this.connectionStringSetting = parameters.connectionStringSetting;
2929
}
3030

31-
public getRequiredProperties() {
32-
return [...super.getRequiredProperties(), "databaseName", "collectionName", "connectionStringSetting"];
31+
public getProperties(): Binding {
32+
if (!this.databaseName) throw new Error("Missing required property 'databaseName'")
33+
if (!this.collectionName) throw new Error("Missing required property 'collectionName'")
34+
if (!this.connectionStringSetting) throw new Error("Missing required property 'connectionStringSetting'")
35+
36+
const properties = {
37+
path: this.databaseName,
38+
collectionName: this.collectionName,
39+
connectionStringSetting: this.connectionStringSetting
40+
};
41+
return Object.assign({}, super.getProperties(), properties);
3342
}
3443
}
3544

@@ -96,12 +105,26 @@ export class CosmosDbTrigger extends CosmosDbBinding implements Trigger {
96105
this.preferredLocations = parameters.preferredLocations;
97106
}
98107

99-
public getOptionalProperties() {
100-
return [...super.getOptionalProperties(), "leaseCollectionName", "createLeaseCollectionIfNotExists",
101-
"leaseConnectionStringSetting", "leaseDatabaseName", "leasesCollectionThroughput",
102-
"leaseCollectionPrefix", "feedPollDelay", "leaseAcquireInterval", "leaseExpirationInterval",
103-
"leaseRenewInterval", "checkpointFrequency", "maxItemsPerInvocation", "startFromBeginning",
104-
"preferredLocations"];
108+
public getProperties(): Binding {
109+
const coreProperties = super.getProperties();
110+
111+
const cosmosProperties = {
112+
leaseCollectionName: this.leaseCollectionName,
113+
createLeaseCollectionIfNotExists: this.createLeaseCollectionIfNotExists,
114+
leaseConnectionStringSetting: this.leaseConnectionStringSetting,
115+
leaseDatabaseName: this.leaseDatabaseName,
116+
leasesCollectionThroughput: this.leasesCollectionThroughput,
117+
leaseCollectionPrefix: this.leaseCollectionPrefix,
118+
feedPollDelay: this.feedPollDelay,
119+
leaseAcquireInterval: this.leaseAcquireInterval,
120+
leaseExpirationInterval: this.leaseExpirationInterval,
121+
leaseRenewInterval: this.leaseRenewInterval,
122+
checkpointFrequency: this.checkpointFrequency,
123+
maxItemsPerInvocation: this.maxItemsPerInvocation,
124+
startFromBeginning: this.startFromBeginning,
125+
preferredLocations: this.preferredLocations
126+
};
127+
return Object.assign({}, coreProperties, cosmosProperties);
105128
}
106129
}
107130

@@ -131,12 +154,18 @@ export class CosmosDbInput extends CosmosDbBinding implements InputBinding {
131154
this.preferredLocations = parameters.preferredLocations;
132155
}
133156

134-
public getRequiredProperties() {
135-
return [...super.getRequiredProperties(), "id", "partitionKey"];
136-
}
137-
138-
public getOptionalProperties() {
139-
return [...super.getOptionalProperties(), "sqlQuery", "preferredLocations"];
157+
public getProperties(): Binding {
158+
const coreProperties = super.getProperties();
159+
if (!this.id) throw new Error("Missing required property 'id'")
160+
if (!this.partitionKey) throw new Error("Missing required property 'partitionKey'")
161+
162+
const cosmosProperties = {
163+
id: this.id,
164+
partitionKey: this.partitionKey,
165+
sqlQuery: this.sqlQuery,
166+
preferredLocations: this.preferredLocations
167+
};
168+
return Object.assign({}, coreProperties, cosmosProperties);
140169
}
141170
}
142171

@@ -169,11 +198,17 @@ export class CosmosDbOutput extends CosmosDbBinding implements OutputBinding {
169198
this.useMultipleWriteLocations = parameters.useMultipleWriteLocations;
170199
}
171200

172-
public getRequiredProperties() {
173-
return [...super.getRequiredProperties(), "partitionKey"];
174-
}
175-
176-
public getOptionalProperties() {
177-
return [...super.getOptionalProperties(), "createIfNotExists", "collectionThroughput", "preferredLocations", "useMultipleWriteLocations"];
201+
public getProperties(): Binding {
202+
const coreProperties = super.getProperties();
203+
if (!this.partitionKey) throw new Error("Missing required property 'partitionKey'")
204+
205+
const cosmosProperties = {
206+
partitionKey: this.partitionKey,
207+
createIfNotExists: this.createIfNotExists,
208+
collectionThroughput: this.collectionThroughput,
209+
preferredLocations: this.preferredLocations,
210+
useMultipleWriteLocations: this.useMultipleWriteLocations
211+
};
212+
return Object.assign({}, coreProperties, cosmosProperties);
178213
}
179214
}

bindings/core/eventHubBinding.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BindingBase, Trigger, InputBinding, OutputBinding } from "../../src/types/bindings/bindings"
1+
import { BindingBase, Trigger, Binding, OutputBinding } from "../../src/types/bindings"
22

33
/**
44
* EventHub Binding
@@ -24,8 +24,16 @@ class EventHubBinding extends BindingBase {
2424
this.connection = parameters.connection;
2525
}
2626

27-
public getRequiredProperties() {
28-
return [...super.getRequiredProperties(), "path", "connection"];
27+
public getProperties(): Binding {
28+
const coreProperties = super.getProperties();
29+
if (!this.path) throw new Error("Missing required property 'path'")
30+
if (!this.connection) throw new Error("Missing required property 'connection'")
31+
32+
const eventHubProperties = {
33+
path: this.path,
34+
connection: this.connection
35+
};
36+
return Object.assign({}, coreProperties, eventHubProperties);
2937
}
3038
}
3139

@@ -54,12 +62,15 @@ export class EventHubTrigger extends EventHubBinding implements Trigger {
5462
this.cardinality = parameters.cardinality;
5563
}
5664

57-
public getRequiredProperties() {
58-
return [...super.getRequiredProperties(), "consumerGroup"];
59-
}
65+
public getProperties(): Binding {
66+
const coreProperties = super.getProperties();
67+
if (!this.consumerGroup) throw new Error("Missing required property 'consumerGroup'")
6068

61-
public getOptionalProperties() {
62-
return [...super.getOptionalProperties(), "cardinality"];
69+
const eventHubProperties = {
70+
consumerGroup: this.consumerGroup,
71+
cardinality: this.cardinality
72+
};
73+
return Object.assign({}, coreProperties, eventHubProperties);
6374
}
6475
}
6576

bindings/core/httpBinding.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Trigger, OutputBinding, TriggerType } from "../../src/types/bindings/bindings"
1+
import { Trigger, OutputBinding, TriggerType, Binding } from "../../src/types/bindings"
22

33
export const HttpTriggerType: TriggerType = "httpTrigger";
44

@@ -39,12 +39,21 @@ export class HttpTrigger implements Trigger {
3939
this.webHookType = parameters.webHookType;
4040
}
4141

42-
public getRequiredProperties() {
43-
return ["name", "type", "direction", "authLevel"];
44-
}
42+
public getProperties(): Binding {
43+
if (!this.name) throw new Error("Missing required property 'name'")
44+
if (!this.type) throw new Error("Missing required property 'type'")
45+
if (!this.direction) throw new Error("Missing required property 'direction'")
46+
if (!this.authLevel) throw new Error("Missing required property 'authLevel'")
4547

46-
public getOptionalProperties() {
47-
return ["route", "webHookType", "methods"];
48+
return {
49+
name: this.name,
50+
type: this.type,
51+
direction: this.direction,
52+
authLevel: this.authLevel,
53+
route: this.route,
54+
webHookType: this.webHookType,
55+
methods: this.methods
56+
};
4857
}
4958
}
5059

@@ -59,11 +68,15 @@ export class HttpResponse implements OutputBinding {
5968
this.name = parameters.bindingName;
6069
}
6170

62-
public getRequiredProperties() {
63-
return ["name", "type", "direction"];
64-
}
71+
public getProperties(): Binding {
72+
if (!this.name) throw new Error("Missing required property 'name'")
73+
if (!this.type) throw new Error("Missing required property 'type'")
74+
if (!this.direction) throw new Error("Missing required property 'direction'")
6575

66-
getOptionalProperties() {
67-
return [];
76+
return {
77+
name: this.name,
78+
type: this.type,
79+
direction: this.direction
80+
};
6881
}
6982
}

bindings/core/queueBinding.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BindingBase, Trigger, OutputBinding, TriggerType } from "../../src/types/bindings/bindings"
1+
import { BindingBase, Binding, Trigger, OutputBinding, TriggerType } from "../../src/types/bindings"
22

33
export const QueueTriggerType: TriggerType = "queueTrigger";
44

@@ -26,8 +26,16 @@ class QueueBinding extends BindingBase {
2626
this.queueName = parameters.queueName;
2727
}
2828

29-
public getRequiredProperties() {
30-
return [...super.getRequiredProperties(), "queueName", "connection"];
29+
public getProperties(): Binding {
30+
const coreProperties = super.getProperties();
31+
if (!this.queueName) throw new Error("Missing required property 'queueName'")
32+
if (!this.connection) throw new Error("Missing required property 'connection'")
33+
34+
const queueProperties = {
35+
queueName: this.queueName,
36+
connection: this.connection
37+
};
38+
return Object.assign({}, coreProperties, queueProperties);
3139
}
3240
}
3341

bindings/core/serviceBusBinding.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BindingBase, Trigger, OutputBinding } from "../../src/types/bindings/bindings"
1+
import { BindingBase, Trigger, OutputBinding, Binding } from "../../src/types/bindings"
22

33
/**
44
* Service bus binding
@@ -40,15 +40,21 @@ class ServiceBusBinding extends BindingBase {
4040
this.subscriptionName = parameters.subscriptionName;
4141
this.connection = parameters.connection;
4242
this.accessRights = parameters.accessRights;
43-
this.dataType = parameters.dataType;
4443
}
4544

46-
public getRequiredProperties() {
47-
return [...super.getRequiredProperties(), "connection", "subscriptionName", "connection"];
48-
}
45+
public getProperties(): Binding {
46+
const coreProperties = super.getProperties();
47+
if (!this.connection) throw new Error("Missing required property 'connection'")
48+
if (!this.subscriptionName) throw new Error("Missing required property 'subscriptionName'")
4949

50-
public getOptionalProperties() {
51-
return [...super.getOptionalProperties(), "queueName", "topicName", "accessRights"];
50+
const serviceBusProperties = {
51+
queueName: this.queueName,
52+
connection: this.connection,
53+
subscriptionName: this.subscriptionName,
54+
topicName: this.topicName,
55+
accessRights: this.accessRights
56+
};
57+
return Object.assign({}, coreProperties, serviceBusProperties);
5258
}
5359
}
5460

bindings/core/timerBinding.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BindingBase, Trigger } from "../../src/types/bindings/bindings"
1+
import { BindingBase, Trigger, Binding } from "../../src/types/bindings"
22

33
/**
44
* Timer binding
@@ -31,11 +31,15 @@ export class TimerTrigger extends BindingBase implements Trigger {
3131
this.runOnStartup = parameters.runOnStartup;
3232
}
3333

34-
public getRequiredProperties() {
35-
return [...super.getRequiredProperties(), "schedule"];
36-
}
34+
public getProperties(): Binding {
35+
const coreProperties = super.getProperties();
36+
if (!this.schedule) throw new Error("Missing required property 'schedule'")
3737

38-
public getOptionalProperties() {
39-
return [...super.getOptionalProperties(), "useMonitor", "runOnStartup"];
38+
const serviceBusProperties = {
39+
schedule: this.schedule,
40+
useMonitor: this.useMonitor,
41+
runOnStartup: this.runOnStartup
42+
};
43+
return Object.assign({}, coreProperties, serviceBusProperties);
4044
}
4145
}

0 commit comments

Comments
 (0)